diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2010-02-23 21:09:52 +0000 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2010-02-23 21:09:52 +0000 |
commit | 86148178754c5403067df8234df2f9bb85c733a7 (patch) | |
tree | e6a839bc428d76fe5b86e58c4460d5d6a00e06aa /Lib/csv.py | |
parent | 92bd059c678e85df3c6fff24dbf4b8b7b27b61bd (diff) | |
download | cpython-git-86148178754c5403067df8234df2f9bb85c733a7.tar.gz |
Fix #1537721: add writeheader() method to csv.DictWriter.
Reviewed by skip.montanaro and thomas.wouters.
Diffstat (limited to 'Lib/csv.py')
-rw-r--r-- | Lib/csv.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/csv.py b/Lib/csv.py index 3db5dac5db..1df506230f 100644 --- a/Lib/csv.py +++ b/Lib/csv.py @@ -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] |