You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to convert dialect descriptions to the equivalent set of formatting parameters in python. It appears that this is not possible, because naively translating a "doubleQuote": true to doublequote=True, ecapechar='"' in python will fail as exemplified with this CSV:
COL1,COL2
"quoted, "" content",val2
and the snippet of python 3 below. Note that setting escapechar to '\\' indepent of doublequote succeeds.
importcsvcsv.field_size_limit(20) # this limits the maximal field length to just a bit above what would be required in our examplewithopen('escape_char.csv') asfp:
print(list(csv.reader(fp, escapechar='\\', doublequote=True))[:2])
withopen('escape_char.csv') asfp:
print(list(csv.reader(fp, escapechar='"', doublequote=True))[:2])
The python code succeeds for the first attempt at reading and fails for the second:
$ python3 escape_char.py
[['COL1', 'COL2'], ['quoted, " content', 'val2']]
Traceback (most recent call last):
File "escape_char.py", line 9, in <module>
print(list(csv.reader(fp, escapechar='"', doublequote=True))[:2])
_csv.Error: field larger than field limit (20)
The text was updated successfully, but these errors were encountered:
I'm trying to convert dialect descriptions to the equivalent set of formatting parameters in python. It appears that this is not possible, because naively translating a
"doubleQuote": true
todoublequote=True, ecapechar='"'
in python will fail as exemplified with this CSV:and the snippet of python 3 below. Note that setting
escapechar
to'\\'
indepent ofdoublequote
succeeds.The python code succeeds for the first attempt at reading and fails for the second:
The text was updated successfully, but these errors were encountered: