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.

classification
Title: csv.DictWriter: Include offending name in error message
Type: enhancement Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, ggenellina, mark-roberts
Priority: normal Keywords:

Created on 2007-01-13 14:53 by ggenellina, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg54977 - (view) Author: Gabriel Genellina (ggenellina) Date: 2007-01-13 14:53
In csv.py, class DictWriter, method _dict_to_list, when rowdict contains a key that is not a known field name, a ValueError is raised, but no reference to the offending name is given.
As the code iterates along the dict keys, and stops at the first unknown one, its trivial to include such information.
Replace lines:

    if k not in self.fieldnames:
        raise ValueError, "dict contains fields not in fieldnames"

with:

    if k not in self.fieldnames:
        raise ValueError, "dict contains field not in fieldnames: %r" % k
msg54978 - (view) Author: Mark Roberts (mark-roberts) Date: 2007-01-15 00:04
Even better would be a list of all extraneous fields fields.

I offered patch 1635454.
msg54979 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-03-13 09:32
Patch was applied, closing this as Accepted.
History
Date User Action Args
2022-04-11 14:56:22adminsetgithub: 44457
2007-01-13 14:53:04ggenellinacreate