Fix #1537721: add writeheader() method to csv.DictWriter.

Reviewed by skip.montanaro and thomas.wouters.
This commit is contained in:
Dirkjan Ochtman 2010-02-23 21:09:52 +00:00
parent 92bd059c67
commit 8614817875
4 changed files with 20 additions and 0 deletions

View file

@ -132,6 +132,10 @@ class DictWriter:
self.extrasaction = extrasaction
self.writer = writer(f, dialect, *args, **kwds)
def writeheader(self):
header = dict(zip(self.fieldnames, self.fieldnames))
self.writerow(header)
def _dict_to_list(self, rowdict):
if self.extrasaction == "raise":
wrong_fields = [k for k in rowdict if k not in self.fieldnames]