On Sep 5, 11:57 am, Bjoern Schliessmann <usenet-
[EMAIL PROTECTED]> wrote:
>  [EMAIL PROTECTED] wrote:
> > I would use a counter in a for loop using the readline method to
> > iterate over the 20,000 line file.
>
> file objects are iterables themselves, so there's no need to do that
> by using a method.

Very true! Darn it!

>
> > Reset the counter every 5 lines/ iterations and close the file.
>
> I'd use a generator that fetches five lines of the file per
> iteration and iterate over it instead of the file directly.
>

I still haven't figured out how to use generators, so this didn't even
come to mind. I usually see something like this example for reading a
file:

f = open(somefile)
for line in f:
    # do something


http://docs.python.org/tut/node9.html

Okay, so they didn't use readline. I wonder where I saw that.

> > Have fun!
>
> Definitely -- and also do your homework yourself :)
>
> Regards,
>
> Björn
>
> --
> BOFH excuse #339:
>
> manager in the cable duct

Mike

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to