summaryrefslogtreecommitdiffstats
path: root/Lib/csv.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/csv.py')
-rw-r--r--Lib/csv.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/Lib/csv.py b/Lib/csv.py
index 45570f7..6ee12c8 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):