summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2007-03-13 09:32:11 (GMT)
committerGeorg Brandl <georg@python.org>2007-03-13 09:32:11 (GMT)
commit94fe3f58d07f1ae5e9ffb10f149498b09aa12a25 (patch)
treefeb10545d68c22d4b986c9d7e082968dd6e47aa9
parentceede5c35988264ac2ca012c07a06270f992ac09 (diff)
downloadcpython-94fe3f58d07f1ae5e9ffb10f149498b09aa12a25.zip
cpython-94fe3f58d07f1ae5e9ffb10f149498b09aa12a25.tar.gz
cpython-94fe3f58d07f1ae5e9ffb10f149498b09aa12a25.tar.bz2
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.
-rw-r--r--Lib/csv.py7
-rw-r--r--Misc/NEWS4
2 files changed, 8 insertions, 3 deletions
diff --git a/Lib/csv.py b/Lib/csv.py
index f213854..8c6b740 100644
--- a/Lib/csv.py
+++ b/Lib/csv.py
@@ -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):
diff --git a/Misc/NEWS b/Misc/NEWS
index 79d242b..33f6d9a 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -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.