Message242787
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. |
|
Date |
User |
Action |
Args |
2015-05-09 01:05:19 | MiK | set | recipients:
+ MiK |
2015-05-09 01:05:19 | MiK | set | messageid: <1431133519.25.0.806037285537.issue24147@psf.upfronthosting.co.za> |
2015-05-09 01:05:19 | MiK | link | issue24147 messages |
2015-05-09 01:05:18 | MiK | create | |
|