Merged revisions 78384 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r78384 | dirkjan.ochtman | 2010-02-23 16:09:52 -0500 (Tue, 23 Feb 2010) | 4 lines

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

  Reviewed by skip.montanaro and thomas.wouters.
........
This commit is contained in:
R. David Murray 2010-02-23 22:57:58 +00:00
parent 5117b0b0dc
commit be0698b1ad
4 changed files with 20 additions and 0 deletions

View file

@ -127,6 +127,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]