New submission from Samwyse: 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 ---------- components: Library (Lib) messages: 232560 nosy: samwyse priority: normal severity: normal status: open title: csv needs more quoting rules type: enhancement versions: Python 2.7, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue23041> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com