I have these lines of code:
>>> import csv, io
>>> raw_csv = io.StringIO('one,two,three\r1,2,3\r,1,2,3')
>>> reader = csv.DictReader(raw_csv, delimiter=',')
>>> list(reader)
which results the error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".../lib/python3.9/csv.py", line 110, in __next__
self.fieldnames
File ".../lib/python3.9/csv.py", line 97, in fieldnames
self._fieldnames = next(self.reader)
_csv.Error: new-line character seen in unquoted field - do you need to open the file in universal-newline mode?
I found solutions using with open()
but I cannot use it since there is no file path. I also need to use DictReader
.