Author MiK
Recipients MiK
Date 2015-05-09.01:05:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1431133519.25.0.806037285537.issue24147@psf.upfronthosting.co.za>
In-reply-to
Content
Python 2.7.3 (default, Mar 13 2014, 11:03:55) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import csv
>>> class Mon(csv.Dialect):
...     delimiter = ','
...     quotechar = '"'
...     quoting = 0
...     lineterminator = '\n'
... 
>>> f = open('sans_headers.csv','r')
>>> reader = csv.DictReader(f, fieldnames=('code', 'nom', 'texte'), dialect=Mon)
>>> for l in reader:
...     print l
... 
{'nom': 'line_1', 'code': '3', 'texte': 'one line\ntwo lines'}
{'nom': 'line_2', 'code': '5', 'texte': 'one line\nand a quote "iop"";newline'}
{'nom': None, 'code': 'I\'m not a cat"', 'texte': None}
>>> f.seek(0)
>>> reader = csv.DictReader(f, fieldnames=('code', 'nom', 'texte'), delimiter=',', quotechar='"', quoting=0, lineterminator='\n')
>>> for l in reader:
...     print l
... 
{'nom': 'line_1', 'code': '3', 'texte': 'one line\ntwo lines'}
{'nom': 'line_2', 'code': '5', 'texte': 'one line\nand a quote "iop";newline\nI\'m not a cat'}
>>> 



If I use a subclass of csv.Dialect with the same attribute that I should use with keywords in calling csv.DictReader I don't get the same behaviour.
History
Date User Action Args
2015-05-09 01:05:19MiKsetrecipients: + MiK
2015-05-09 01:05:19MiKsetmessageid: <1431133519.25.0.806037285537.issue24147@psf.upfronthosting.co.za>
2015-05-09 01:05:19MiKlinkissue24147 messages
2015-05-09 01:05:18MiKcreate