||Parser for CSV files.|
Parses CSV files including all subtleties such as:
* commas in fields
* double quotes in fields
* embedded newlines in fields
- Examples of programs that produce such beasts include
MySQL and Excel
For a higher-level, friendlier CSV class with many conveniences,
see DataTable (which uses this class for its parsing).
records = 
parse = CSVParser().parse
for line in lines:
results = parse(line)
if results is not None:
The algorithm was taken directly from the open source Python
It would be nice to use the csv module when present, since it is
substantially faster. Before that can be done, it needs to support
allowComments and stripWhitespace, and pass the TestCSVParser.py
||Methods defined here:|
- __init__(self, allowComments=True, stripWhitespace=True, fieldSep=',', autoReset=True, doubleQuote=True)
- Create a new CSV parser.
allowComments: If true (the default), then comment lines using
the Python comment marker are allowed.
stripWhitespace: If true (the default), then left and right whitespace
is stripped off from all fields.
fieldSep: Defines the field separator string (a comma by default).
autoReset: If true (the default), recover from errors automatically.
doubleQuote: If true (the default), assume quotes in fields are
escaped by appearing doubled.
- endQuotedField(self, c)
- inField(self, c)
- inQuotedField(self, c)
- parse(self, line)
- Parse a single line and return a list of string fields.
Returns None if the CSV record contains embedded newlines and
the record is not yet complete.
- quoteInField(self, c)
- quoteInQuotedField(self, c)
- Reset the parser.
Resets the parser to a fresh state in order to recover from
exceptions. But if autoReset is true (the default), this is
- startField(self, c)
- startRecord(self, c)
Data descriptors defined here:
- dictionary for instance variables (if defined)
- list of weak references to the object (if defined)