[issue40825] Add a "strict" parameter to csv.writer and csv.DictWriter

Eric V. Smith report at bugs.python.org
Sat May 30 08:31:33 EDT 2020


New submission from Eric V. Smith <eric at trueblade.com>:

Currently, the csv library calls str() on each value it writes. This can lead to surprising behavior, see issue40762 for example.

On the other hand, for writing the documentation says that the values must be strings or numbers.

The proposed "strict" argument would raise a TypeError if the supplied values are not strings, numbers, or None.

See https://github.com/python/cpython/blob/ba1c2c85b39fbcb31584c20f8a63fb87f9cb9c02/Modules/_csv.c#L1203 for where str() is called.

The documentation should be changed to note that None is allowed. Currently, None results in an empty string. I'm not proposing to change this, just document it as one of the allowed types.

How to check for "value is a number" needs to be decided.

----------
messages: 370380
nosy: eric.smith
priority: normal
severity: normal
status: open
title: Add a "strict" parameter to csv.writer and csv.DictWriter
type: enhancement
versions: Python 3.10

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40825>
_______________________________________


More information about the Python-bugs-list mailing list