diff options
author | Georg Brandl <georg@python.org> | 2007-03-13 09:32:11 +0000 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2007-03-13 09:32:11 +0000 |
commit | 588f1d8939dfd5fa973185d4a8a572605628bf15 (patch) | |
tree | a7794571541b7d9d2a18c74e5db574f6e5ef8817 /Lib/csv.py | |
parent | 13ca6a24ebca2691f9da5987ed7c7e4698665d7f (diff) | |
download | cpython-588f1d8939dfd5fa973185d4a8a572605628bf15.tar.gz |
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.
Diffstat (limited to 'Lib/csv.py')
-rw-r--r-- | Lib/csv.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Lib/csv.py b/Lib/csv.py index f213854783..8c6b740127 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): |