This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Benjamin Schollnick
Recipients Benjamin Schollnick, skip.montanaro, xtreak
Date 2019-07-30.13:05:38
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1564491939.18.0.191099088464.issue37709@roundup.psfhosted.org>
In-reply-to
Content
This is tested under python 3...

filename = "csv_Sample.csv"
from csv import DictReader
datafile = open(filename, 'r')
data = csv.DictReader(datafile, lineterminator = '\x07', delimiter='\x06')
print(next(data))
    OrderedDict([('Field1', 'A'), ('Field2', 'B'), ('Field3', 'C'), ('Field4', 'D'), ('Field5', 'E'), ('Field6', 'F'), ('Field7', 'G'), ('Field8', 'H'), ('Field9', 'I'), ('Field10\x07', 'J\x07')])
print(ord(data.reader.dialect.lineterminator))

So it's untested under python 2, since I've stopped developing under Py2.  

I noticed the note in the CSV reader documentation, *AFTER* I diagnosed the issue with the CSV reader...  Which is why I opened the bug / feature enhancement request, since this is an very odd edge case.

I agree 90+% of all CSVs are going to be \n line terminated, but if we offer it for writing, we should offer it for reading.

The main emphasis here is this code will not working in the real world, eg.

filename = "csvFile.csv"
from csv import DictReader, DictWriter
import csv
with open(filename, mode='w') as output_file:
    outcsv = csv.writer(output_file, delimiter=',', lineterminator=";")
    outcsv.writerow(['John Cleese', 'CEO', 'March'])
    outcsv.writerow(['Graham Chapman', 'CFO', 'November'])
    outcsv.writerow(['Terry Jones', 'Animation', 'March'])
    outcsv.writerow(['Eric Idle', 'Laugh Track', 'November'])
    outcsv.writerow(['Michael Palin', 'Snake Wrangler', 'March'])

with open(filename, mode='r') as input_file:
    csv_reader = csv.reader(input_file, delimiter=',', lineterminator=";")
    for row in csv_reader:
        print(row)
History
Date User Action Args
2019-07-30 13:05:39Benjamin Schollnicksetrecipients: + Benjamin Schollnick, skip.montanaro, xtreak
2019-07-30 13:05:39Benjamin Schollnicksetmessageid: <1564491939.18.0.191099088464.issue37709@roundup.psfhosted.org>
2019-07-30 13:05:39Benjamin Schollnicklinkissue37709 messages
2019-07-30 13:05:38Benjamin Schollnickcreate
Morty Proxy This is a proxified and sanitized view of the page, visit original site.