[Python-checkins] r54327 - in python/trunk: Lib/csv.py Misc/NEWS

georg.brandl python-checkins at python.org
Tue Mar 13 10:32:14 CET 2007


Author: georg.brandl
Date: Tue Mar 13 10:32:11 2007
New Revision: 54327
Modified:
 python/trunk/Lib/csv.py
 python/trunk/Misc/NEWS
Log:
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.
Modified: python/trunk/Lib/csv.py
==============================================================================
--- python/trunk/Lib/csv.py	(original)
+++ python/trunk/Lib/csv.py	Tue Mar 13 10:32:11 2007
@@ -115,9 +115,10 @@
 
 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):
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Tue Mar 13 10:32:11 2007
@@ -168,6 +168,10 @@
 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.
 


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /