xoutil.future.csv
- CSV parsing and writing extensions¶
New in version 1.8.4.
This module extends the standard library’s csv
. You may use it
as a drop-in replacement in many cases.
Avoid importing *
from this module since could be different in Python 2.7
and Python 3.3.
We added the following features.
-
class
xoutil.future.csv.
unix_dialect
[source]¶ Describe the usual properties of Unix-generated CSV files.
Added only in Python 2 for compatibility purposes.
-
xoutil.future.csv.
parse
(data, *dialect, **options)[source]¶ Parse data into a sheet.
This function has the exact parameters protocol as
reader()
parse(data [, dialect='excel'] [, optional keyword options])
Parameters: - data – Can be any object that returns a line of input for each iteration, such as a file object or a list.
- dialect – An optional parameter can be given which is used to define
a set of parameters specific to a particular CSV dialect. It may
be an instance of a subclass of the
Dialect
class or one of the strings returned by thelist_dialects()
function.
The other optional keyword arguments can be given to override individual formatting parameters in the current dialect.
When reading a value,
csv
for Python version 2 doesn’t accept unicode text, so given data lines are forced to bestr
values before processed byreader()
. Each cell is converted to unicode text after read.Returns: The parsed matrix. A short usage example:
>>> from xoutil.future import csv >>> with open('test.csv', newline='') as data: ... matrix = csv.parse(data) ... for row in matrix: ... print(', '.join(row)) Last name, First Name van Rossum, Guido Stallman, Richard