`csv.writer` with `QUOTE_NONE` still requires non-emtpy `quotechar` and `escapechar` · Issue #132813 · python/cpython · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

csv.writer with QUOTE_NONE still requires non-emtpy quotechar and escapechar #132813

Closed
@vadimkantorov

Description

@vadimkantorov

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

Metadata

Metadata

Labels

extension-modulesC modules in the Modules dirstdlibPython modules in the Lib dirtype-featureA feature request or enhancement

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    TMZ Celebrity News – Breaking Stories, Videos & Gossip

    Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

    Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

    🎥 Watch TMZ Live

    TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.