csv module strangeness.

Peter Otten __peter__ at web.de
Wed Aug 30 17:54:45 EDT 2006


tobiah wrote:

>> you may be misreading the docs; the Dialect has no values at all, and
>> must be subclassed (and the subclass must provide settings).
> 
> The docs clearly state what the defaults are, but they are not
> in the code.  It seems so clumsy to have to specify every one
> of these, just to change the delimiter from comma to tab.
> 
> http://docs.python.org/lib/csv-fmt-params.html :
> 
> delimiter
>     A one-character string used to separate fields. It defaults to ','.

Note that you need not bother with a dialect class just to change the
delimiter:

>>> import csv
>>> from cStringIO import StringIO
>>> instream = StringIO(
... "alpha\tbeta\tgamma\r\n"
... "one\ttoo\ttree\r\n")
>>> for row in csv.reader(instream, delimiter="\t"):
...     print row
...
['alpha', 'beta', 'gamma']
['one', 'too', 'tree']

Peter



More information about the Python-list mailing list