It's ...

J. Cliff Dyer jcd at sdf.lonestar.org
Wed Jul 1 11:48:23 EDT 2009


On Tue, 2009-06-30 at 13:24 -0700, Beni Cherniavsky wrote:
> On Jun 24, 11:40 pm, "J. Cliff Dyer" <j... at sdf.lonestar.org> wrote:
> > Also note that you can iterate over a file several times:
> >
> > f = open('foo.txt')
> > for line in f:
> >     print line[0]  # prints the first character of every line
> > for line in f:
> >     print line[1]  #prints the second character of every line
> >
> No, you can't.  The second loop prints nothing!
> A file by default advances forward.  Once you reach the end, you stay
> there.

You are, of course, absolutely right.  Sorry for the misinformation.

:(




More information about the Python-list mailing list