Commit 588f1d89 authored by Georg Brandl's avatar Georg Brandl

Patch #1635454: the csv.DictWriter class now includes the offending

field names in its exception message if you try to write a record with
a dictionary containing fields not in the CSV field names list.
parent 13ca6a24
......@@ -115,9 +115,10 @@ class DictWriter:
def _dict_to_list(self, rowdict):
if self.extrasaction == "raise":
for k in rowdict.keys():
if k not in self.fieldnames:
raise ValueError, "dict contains fields not in fieldnames"
wrong_fields = [k for k in rowdict if k not in self.fieldnames]
if wrong_fields:
raise ValueError("dict contains fields not in fieldnames: " +
", ".join(wrong_fields))
return [rowdict.get(key, self.restval) for key in self.fieldnames]
def writerow(self, rowdict):
......
......@@ -168,6 +168,10 @@ Core and builtins
Library
-------
- Patch #1635454: the csv.DictWriter class now includes the offending
field names in its exception message if you try to write a record with
a dictionary containing fields not in the CSV field names list.
- Patch #1668100: urllib2 now correctly raises URLError instead of
OSError if accessing a local file via the file:// protocol fails.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment