mirror of
https://github.com/python/cpython.git
synced 2025-07-28 13:44:43 +00:00
Fix #1537721: add writeheader() method to csv.DictWriter.
Reviewed by skip.montanaro and thomas.wouters.
This commit is contained in:
parent
92bd059c67
commit
8614817875
4 changed files with 20 additions and 0 deletions
|
@ -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]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue