Author Pavel
Recipients Pavel, docs@python
Date 2017-07-15.14:48:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1500130085.47.0.354601054193.issue30937@psf.upfronthosting.co.za>
In-reply-to
Content
At the very beginning the csv module documentation (https://docs.python.org/3.7/library/csv.html) advises to open files passing newline='' parameter though three examples don't include it:

Here are the examples:

1:
>>> import csv
>>> with open('names.csv') as csvfile:
...     reader = csv.DictReader(csvfile)
...     for row in reader:
...         print(row['first_name'], row['last_name'])
...
Eric Idle
John Cleese

>>> print(row)
OrderedDict([('first_name', 'John'), ('last_name', 'Cleese')])

2:
import csv

with open('names.csv', 'w') as csvfile:
    fieldnames = ['first_name', 'last_name']
    writer = csv.DictWriter(csvfile, fieldnames=fieldnames)

    writer.writeheader()
    writer.writerow({'first_name': 'Baked', 'last_name': 'Beans'})
    writer.writerow({'first_name': 'Lovely', 'last_name': 'Spam'})
    writer.writerow({'first_name': 'Wonderful', 'last_name': 'Spam'})

3:
with open('example.csv') as csvfile:
    dialect = csv.Sniffer().sniff(csvfile.read(1024))
    csvfile.seek(0)
    reader = csv.reader(csvfile, dialect)
    # ... process CSV file contents here ...
History
Date User Action Args
2017-07-15 14:48:05Pavelsetrecipients: + Pavel, docs@python
2017-07-15 14:48:05Pavelsetmessageid: <1500130085.47.0.354601054193.issue30937@psf.upfronthosting.co.za>
2017-07-15 14:48:05Pavellinkissue30937 messages
2017-07-15 14:48:04Pavelcreate