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 samwyse
Recipients samwyse
Date 2014-12-12.16:36:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1418402205.61.0.685044268577.issue23041@psf.upfronthosting.co.za>
In-reply-to
Content
The csv module currently implements four quoting rules for dialects: QUOTE_MINIMAL, QUOTE_ALL, QUOTE_NONNUMERIC and QUOTE_NONE.  These rules treat values of None the same as an empty string, i.e. by outputting two consecutive quotes.  I propose the addition of two new rules, QUOTE_NOTNULL and QUOTE_STRINGS.  The former behaves like QUOTE_ALL while the later behaves like QUOTE_NONNUMERIC, except that in both cases values of None are output as an empty field.  Examples follow.


Current behavior (which will remain unchanged)

>>> csv.register_dialect('quote_all', quoting=csv.QUOTE_ALL)
>>> csv.writer(sys.stdout, dialect='quote_all').writerow(['foo', None, 42])
"foo","","42"

>>> csv.register_dialect('quote_nonnumeric', quoting=csv.QUOTE_NONNUMERIC)
>>> csv.writer(sys.stdout, dialect='quote_nonnumeric').writerow(['foo', None, 42])
"foo","",42


Proposed behavior

>>> csv.register_dialect('quote_notnull', quoting=csv.QUOTE_NOTNULL)
>>> csv.writer(sys.stdout, dialect='quote_notnull').writerow(['foo', None, 42])
"foo",,"42"

>>> csv.register_dialect('quote_strings', quoting=csv.QUOTE_STRINGS)
>>> csv.writer(sys.stdout, dialect='quote_strings').writerow(['foo', None, 42])
"foo",,42
History
Date User Action Args
2014-12-12 16:36:45samwysesetrecipients: + samwyse
2014-12-12 16:36:45samwysesetmessageid: <1418402205.61.0.685044268577.issue23041@psf.upfronthosting.co.za>
2014-12-12 16:36:45samwyselinkissue23041 messages
2014-12-12 16:36:45samwysecreate