csv.DictWriter.write_header()

John Machin sjmachin at lexicon.net
Wed Aug 12 22:24:19 EDT 2009


On Aug 13, 6:45 am, Alan G Isaac <alan.is... at gmail.com> wrote:
> Given a csv.DictWriter instance `dw`
> I think it would be nice to be able to
> say dw.write_header()
> instead of
> dw.writer.writerow(dw.fieldnames)
>
> Good idea?

Yes, it's a brilliant idea. All you have to do is insert the following
lines in your code after importing csv:

csv.DictWriter.write_header = (
    lambda dw: dw.writer.writerow(dw.fieldnames)
    )



More information about the Python-list mailing list