iterating over lines in a file
Thomas Wouters
thomas at xs4all.net
Thu Jul 20 08:39:00 EDT 2000
On Thu, Jul 20, 2000 at 10:16:33AM +0000, Remco Gerlich wrote:
> > > while (line = <FILE>) { block; }
> > The easiest way:
> > for line in file.readlines():
> > block
> But that would read the whole thing into memory, and he doesn't want that.
> Wouldn't an xreadlines() method on file objects be cool?
There's the 'fileinput' module, which is almost exactly that. (It does some
extra things as well, if you wish ;)
--
Thomas Wouters <thomas at xs4all.net>
Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
More information about the Python-list
mailing list