[New-bugs-announce] [issue44585] csv library does not correctly interpret some files
Marco E.
report at bugs.python.org
Thu Jul 8 09:13:28 EDT 2021
New submission from Marco E. <marco.esposito at gmail.com>:
The CSV library does not correctly interpret files in the following format (test.csv):
"A" ,"B" ,"C"
"aaaaaa","bbbbbbb","cccc"
"aaaaa" ,"bbbbbb" ,"ccc"
"aaaa" ,"bbbbb" ,"cc"
This program:
import csv
from pathlib import Path
def main():
with Path('test.csv').open('rt') as csv_file:
csv.register_dialect('my_dialect', quotechar='"', delimiter=',',
quoting=csv.QUOTE_ALL, skipinitialspace=True)
reader = csv.DictReader(csv_file, dialect='my_dialect')
for row in reader:
print(row)
if __name__ == '__main__':
main()
produces the following output:
{'A ': 'aaaaaa', 'B ': 'bbbbbbb', 'C': 'cccc'}
{'A ': 'aaaaa ', 'B ': 'bbbbbb ', 'C': 'ccc'}
{'A ': 'aaaa ', 'B ': 'bbbbb ', 'C': 'cc'}
this instead is the expected result:
{'A': 'aaaaaa', 'B': 'bbbbbbb', 'C': 'cccc'}
{'A': 'aaaaa', 'B': 'bbbbbb', 'C': 'ccc'}
{'A': 'aaaa', 'B': 'bbbbb', 'C': 'cc'}
why?
Thank you,
Marco
----------
components: Library (Lib)
messages: 397139
nosy: voidloop
priority: normal
severity: normal
status: open
title: csv library does not correctly interpret some files
versions: Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44585>
_______________________________________
More information about the New-bugs-announce
mailing list