while c = f.read(1)

Robert Kern rkern at ucsd.edu
Fri Aug 19 07:22:05 EDT 2005


en.karpachov at ospaz.ru wrote:

> import itertools
> f = open("blah.txt", "r")
> for c in itertools.chain(*f):
>      print c
>      # ...
> 
> The "f" is iterable itself, yielding a new line from the file every time.
> Lines are iterable as well, so the itertools.chain iterates through each
> line and yields a character.

As far as I can tell, that code is just going to read the whole file in 
when Python does the *arg expansion. What's the point?

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter




More information about the Python-list mailing list