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 voidloop
Recipients voidloop
Date 2021-07-08.13:13:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1625750008.87.0.451821188518.issue44585@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2021-07-08 13:13:28voidloopsetrecipients: + voidloop
2021-07-08 13:13:28voidloopsetmessageid: <1625750008.87.0.451821188518.issue44585@roundup.psfhosted.org>
2021-07-08 13:13:28voidlooplinkissue44585 messages
2021-07-08 13:13:28voidloopcreate