Python Success Stories or Nightmares

Andrew Bennetts andrew-pythonlist at puzzling.org
Sun Feb 2 22:55:43 EST 2003


On Sun, Feb 02, 2003 at 07:14:27PM -0800, Paul Rubin wrote:
> Andrew Bennetts <andrew-pythonlist at puzzling.org> writes:
> > If you do this in Python alot, and really really want a one-liner,
> > you could do:
> > 
> >     def getc(f):
> >         while 1:
> >             c = f.read(1)
> >             if not c:
> >                 return
> >             yield c
> > 
> > Which you could then use as:
> > 
> >     for c in getc(f):
> >         ...
> > 
> > That gives you the one-liner without all the punctuation.  Good enough?
> 
> Yucch.  I can't imagine how that could be considered easier to understand
> than the assignment-inside-expression idiom.

You're right; getc is a horrible name for it...  it should probably be
something like "readCharIterator" <wink>

-Andrew.






More information about the Python-list mailing list