csv documentation error? (was Re: csv - howto specify fmtparam parameters)

Helmut Jarausch jarausch at igpm.rwth-aachen.de
Thu Aug 21 11:48:12 CEST 2003


Many thanks for the hint,
still I am curious: is the documentation in error?
It says
class DictReader(csvfile,fieldnames[,restkey=None[,dialect='excel'
    [,fmtparam]]])
and the documentation for 'reader' says
The other optional parameter 'fmtparam' keyword arguments can be given 
to override individual formatting parameters, see section, ``Dialects 
and Formatting Parameters''
and there ... In addition to, or instead of, the 'dialect' parameter, 
the programmer can alos specify individual formatting parameters, which 
have the same names as the attributes defined above for the 'Dialect' class.

Peter Otten wrote:
> Seems that the docs are wrong. The following should work:
> 
> import csv
> csv_file = file('test.csv')
> 
> class MyDialect(csv.excel):
>     lineterminator = "\n"
> 
> dr = csv.DictReader(csv_file,['Matr','Name','Vorname','PZ','MP'],\
>       dialect=MyDialect)
> 
> for s in dr:
>      print s
> 
> Peter

 > Helmut Jarausch wrote:
 > import csv
 > csv_file= file('test.csv')

 > Inp= csv.DictReader(csv_file,['Matr','Name','Vorname','PZ','MP'],\
 >      lineterminator='\n')

 > for S in Inp:
 >     print S

 > but I get
 > Traceback (most recent call last):
 >   File "/home/jarausch/Python/My/test_csv.py", line 5, in -toplevel-
 >     lineterminator='\n')
 > TypeError: __init__() got an unexpected keyword argument 'lineterminator'

 > What went wrong?



-- 
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany





More information about the Python-list mailing list