CSV without first line?
Steve Holden
steve at holdenweb.com
Sun Jul 15 09:26:22 EDT 2007
Sebastian Bassi wrote:
> Hi,
>
> In my CSV file, the first line has the name of the variables. So the
> data I want to parse resides from line 2 up to the end. Here is what I
> do:
>
> import csv
> lines=csv.reader(open("MYFILE"))
> lines.next() #this is just to avoid the first line
> for line in lines:
> DATA PARSING
>
> This works fine. But I don't like to do "lines.next()" just to get rid
> of the first line. So I wonder if the reader function on the csv
> module has something that could let me parse the file from the second
> line (w/o doing that lines.next()).
>
>
That's a perfectly legitimate thing to do, so don't worry about it.
If it makes you feel better you could use the Sniffer class's
has_header() method.
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------
More information about the Python-list
mailing list