mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
#19449: Handle non-string keys when generating 'fieldnames' error.
csv was handling non-string keys fine except for the error message generated when a non-string key was not in 'fieldnames'. Fix by Tomas Grahn, full patch-with-test by Vajrasky Kok (tweaked slightly).
This commit is contained in:
parent
30c5ad2aa2
commit
fb099c9ef1
3 changed files with 16 additions and 1 deletions
|
@ -146,7 +146,7 @@ class DictWriter:
|
|||
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))
|
||||
+ ", ".join([repr(x) for x in wrong_fields]))
|
||||
return [rowdict.get(key, self.restval) for key in self.fieldnames]
|
||||
|
||||
def writerow(self, rowdict):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue