New submission from Tomas Grahn: When csv.DictWriter.writerow is fed a dict with extra fieldnames (and extrasaction='raise') and any of those extra fieldnames aren't strings, a TypeError-exception is thrown. To fix the issue; in csv.py, edit the line: raise ValueError("dict contains fields not in fieldnames: " + ", ".join(wrong_fields))
to: raise ValueError("dict contains fields not in fieldnames: " + ", ".join(repr(wrong_field) for wrong_field in wrong_fields)) Attached is a patch that fixes the problem (works in both 2.6 and 2.7, I haven't tried anything else). Here is a simple test to demonstrate the problem: import cStringIO, csv sio=cStringIO.StringIO() writer=csv.DictWriter(sio, ["foo", "bar"]) writer.writerow({1:"hello", 2:"world"}) ---------- files: csv-patch.diff keywords: patch messages: 201727 nosy: tomas_grahn priority: normal severity: normal status: open title: csv.DictWriter can't handle extra non-string fields type: behavior versions: Python 2.6, Python 2.7 Added file: http://bugs.python.org/file32425/csv-patch.diff _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue19449> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com