while c = f.read(1)

en.karpachov at ospaz.ru en.karpachov at ospaz.ru
Fri Aug 19 07:30:10 EDT 2005


On 19 Aug 2005 03:43:31 -0700
Paul Rubin wrote:

> <en.karpachov at ospaz.ru> writes:
> > import itertools
> > f = open("blah.txt", "r")
> > for c in itertools.chain(*f):
> 
> But that can burn an unlimited amount of memory if there are long
> stretches of the file with no newlines.  There's no real good way
> around ugly code.

I agree. Moreover, in fact, it is the same as just

for c in f.read():
     # ...

-- 
jk



More information about the Python-list mailing list