Text processing and file creation
kyosohma at gmail.com
kyosohma at gmail.com
Wed Sep 5 14:05:34 EDT 2007
On Sep 5, 11:57 am, Bjoern Schliessmann <usenet-
mail-0306.20.chr0n... at spamgourmet.com> wrote:
> kyoso... at gmail.com 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
More information about the Python-list
mailing list