Looping through File Question

Amit Khemka khemkaamit at gmail.com
Wed Sep 5 13:22:35 CEST 2007


On 9/5/07, Francesco Guerrieri <f.guerrieri at gmail.com> wrote:
> On 9/5/07, planetmatt <planetmatt at gmail.com> wrote:
> > I am a Python beginner.  I am trying to loop through a CSV file which
> > I can do.  What I want to change though is for the loop to start at
> > row 2 in the file thus excluding column headers.
> >
> > At present I am using this statement to initiate a loop though the
> > records:
> >
> > for line in f.readlines():
> >
> > How do I start this at row 2?
> >
>
> you can simply call (and maybe throw away) f.readline() a single time before
> looping.
> If the lenght of the first line is fixed, you can also use f.seek to start
> reading from the second row.
>
> francesco

Btw, if you are trying to read a csv file and parse it, you can save
some work  .. have a look at "csv" module !

-- 
----
Amit Khemka
website: www.onyomo.com
wap-site: www.owap.in



More information about the Python-list mailing list