Bug report
Bug description:
I'd like to output all quotes verbatim, without any escaping/quoting, but this fails:
import csv w = csv.writer(open('test.tsv', 'w'), delimiter = '\t', quoting = csv.QUOTE_NONE) w.writerow(('"hello"', '"world"')) # _csv.Error: need to escape, but no escapechar set
When I set escapechar='' or quotechar='', it also fails:
import csv w = csv.writer(open('test.tsv', 'w'), delimiter = '\t', quoting = csv.QUOTE_NONE, escapechar = '') w.writerow(('"hello"', '"world"')) # TypeError: "escapechar" must be a 1-character string import csv w = csv.writer(open('test.tsv', 'w'), delimiter = '\t', quoting = csv.QUOTE_NONE, quotechar = '') w.writerow(('"hello"', '"world"')) # TypeError: "quotechar" must be a 1-character string
I would suggest that under QUOTE_NONE, escaping of quotes should not be performed at all, or at least allow empty escapechar / quotechar
The workaround / hack I found:
import csv w = csv.writer(open('test.tsv', 'w'), delimiter = '\t', quoting = csv.QUOTE_NONE, quotechar = '\t') w.writerow(('"hello"', '"world"'))
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs
- gh-132813: Fix the csv documentation for quoting and escaping #133209
- gh-132813: Improve error messages for incorrect types and values of csv.Dialog attributes #133241
- [3.14] gh-132813: Improve error messages for incorrect types and values of csv.Dialog attributes (GH-133241) #135050
- [3.14] gh-132813: Fix the csv documentation for quoting and escaping (GH-133209) #136113
- [3.13] gh-132813: Fix the csv documentation for quoting and escaping (GH-133209) #136114