Package wsatools :: Module CSV :: Class File
[hide private]

Class File

source code


Read and write CSV files. Ignores blank and comment lines.

Instance Methods [hide private]
tuple(str)
readline(self)
Returns: Every value in the next line of the file.
source code
None
write(self, values, inQuotes=False)
Write the sequence of values to the file as a line of comma-separated values.
source code
None
writelines(self, sequence, inQuotes=False)
Write a sequence of lines, each containing a sequence of values, to the file in the comma-separated values format.
source code

Inherited from Utilities.ParsedFile: next, readlines

Inherited from file: __delattr__, __enter__, __exit__, __getattribute__, __init__, __iter__, __new__, __repr__, __setattr__, close, fileno, flush, isatty, read, readinto, seek, tell, truncate, xreadlines

Inherited from object: __format__, __hash__, __reduce__, __reduce_ex__, __sizeof__, __str__, __subclasshook__

Static Methods [hide private]
 
autoSetDialect(filePathName, numLinesSniffed=10)
Use sniffDialect() function to automatically set the correct dialect of the CSV file to be read.
source code
 
setDialect(dialect)
Set the current dialect to the one described in the supplied dialect object.
source code
Class Variables [hide private]
  _dialect = 'excel'
CSV dialect.

Inherited from Utilities.ParsedFile: commentMarker, stripEOLComments

Properties [hide private]

Inherited from file: closed, encoding, errors, mode, name, newlines, softspace

Inherited from object: __class__

Method Details [hide private]

autoSetDialect(filePathName, numLinesSniffed=10)
Static Method

source code 

Use sniffDialect() function to automatically set the correct dialect of the CSV file to be read.

Parameters:
  • filePathName (str) - Full path to the CSV file.
  • numLinesSniffed (int) - Number of lines to inspect.

setDialect(dialect)
Static Method

source code 

Set the current dialect to the one described in the supplied dialect object.

Parameters:
  • dialect (classobj) - A class derived from the csv.Dialect class describing the current dialect.

readline(self)

source code 

Retain newline. A non-negative size argument limits the maximum number of bytes to return (an incomplete line may be returned then). Return an empty string at EOF.

Returns: tuple(str)
Every value in the next line of the file.
Overrides: file.readline

write(self, values, inQuotes=False)

source code 

Write the sequence of values to the file as a line of comma-separated values.

Parameters:
  • values (sequence) - A sequence of string-castable values.
  • inQuotes (bool) - If True, encapsulate strings in quotes.
Returns: None
Overrides: file.write

writelines(self, sequence, inQuotes=False)

source code 

Write a sequence of lines, each containing a sequence of values, to the file in the comma-separated values format.

Parameters:
  • sequence (sequence(sequence)) - A sequence for every line that contains a sequence of string-castable objects for every file.
  • inQuotes (bool) - If True, encapsulate strings in quotes.
Returns: None
Overrides: file.writelines