Pythonic use of CSV module to skip headers?

Michael Hoffman at
Sat Dec 4 16:02:45 CET 2004

Skip Montanaro wrote:
> I'm not sure what the use of TABs as delimiters has to do with the OP's
> problem.

Not much. :) I just happen to use tabs more often than commas, so my 
subclass defaults to

> You can create a subclass of DictReader that plucks the first line out as a
> set of titles:
>     class SmartDictReader(csv.DictReader):
>         def __init__(self, f, *args, **kwds):
>             rdr = csv.reader(*args, **kwds)
>             titles =
>             csv.DictReader.__init__(self, f, titles, *args, **kwds)
> Is that what you were suggesting?


> I don't find the couple extra lines of
> code in my original example all that cumbersome to type though.

If you started about half of the programs you write with those extra 
lines, you might <wink>. I'm a strong believer in OnceAndOnlyOnce.

Thanks to Nick Coghlan for pointing out that I no longer need do this in 
Python 2.4.
Michael Hoffman

More information about the Python-list mailing list