Hello, I can't seem to be able to specify the delimiter when building a
DictReader()
I can do:
inf = file('data.csv' )
rd = csv.reader( inf, delimiter=';' )
for row in rd:
# ...
But this is rejected:
inf = file('data.csv' )
headers = inf.readline(). split(';')
rd = csv.DictReader( inf, headers, delimiter=';' )
for row in rd:
# ...
The DictReader constructor fails with a TypeError:
init() got an unexpected keyword argument 'delimiter'
Maybe I am missing something here?
One rather convoluted workaround is the following:
inf = file('data.csv' )
d = csv.Sniffer().s niff(s)
inf.seek(0)
headers = inf.readline(). split(';')
rd = csv.DictReader( inf, headers, dialect=d )
for row in rd:
# ...
If DialectReader does indeed not accept the optional "fmtparam"
then at least the documentation needs fixing. But then again
I may just be misreading it....
TIA,
Bernard.
DictReader()
I can do:
inf = file('data.csv' )
rd = csv.reader( inf, delimiter=';' )
for row in rd:
# ...
But this is rejected:
inf = file('data.csv' )
headers = inf.readline(). split(';')
rd = csv.DictReader( inf, headers, delimiter=';' )
for row in rd:
# ...
The DictReader constructor fails with a TypeError:
init() got an unexpected keyword argument 'delimiter'
Maybe I am missing something here?
One rather convoluted workaround is the following:
inf = file('data.csv' )
d = csv.Sniffer().s niff(s)
inf.seek(0)
headers = inf.readline(). split(';')
rd = csv.DictReader( inf, headers, dialect=d )
for row in rd:
# ...
If DialectReader does indeed not accept the optional "fmtparam"
then at least the documentation needs fixing. But then again
I may just be misreading it....
TIA,
Bernard.
Comment