New submission from Sebastian Bank <sebastian.b...@uni-leipzig.de>:
AFAICT there was an undocumented change in behaviour related to the fix of https://bugs.python.org/issue12178 (also reported in https://bugs.python.org/issue12178#msg397440): Python 3.9 quotes values with escapechar: ``` import csv import io kwargs = {'escapechar': '\\'} value = 'spam\\eggs' print(value) with io.StringIO() as buf: writer = csv.writer(buf, **kwargs) writer.writerow([value]) line = buf.getvalue() print(line.strip()) with io.StringIO(line) as buf: reader = csv.reader(buf, **kwargs) (new_value,), = reader print(new_value) spam\eggs "spam\eggs" spameggs ``` - quotes escapechar - fails to double the escapechar (https://bugs.python.org/issue12178) >From https://docs.python.org/3/library/csv.html#csv.QUOTE_MINIMAL > only quote those fields which contain special characters > such as delimiter, quotechar or any of the characters in > lineterminator. The previous behaviour seems incorrect because escapechar is not explicitly mentioned, but at the same time the docs says 'such as'. The new might better matching the name 'minimal', but at the same time one might regard 'quote when in doubt' as a safer behaviour for the default quoting rule. Python 3.10: https://github.com/python/cpython/blob/5c0eed7375fdd791cc5e19ceabfab4170ad44062/Lib/test/test_csv.py#L207-L208 See also https://github.com/xflr6/csv23/actions/runs/1027687524 ---------- components: Library (Lib) messages: 399188 nosy: ebreck, taleinat, xflr6 priority: normal severity: normal status: open title: csv.writer stopped to quote values with escapechar with csv.QUOTE_MINIMAL in Python 3.10 type: behavior versions: Python 3.10 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue44861> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com