PEP 289: Generator Expressions (please comment)
Erik Max Francis
max at alcyone.com
Thu Oct 23 21:11:45 EDT 2003
rzed wrote:
> I like it! How about in conjunction with the print statement?
> print "%s\n" % (s for s in strlist)
> ??
Presuming you want this to result in a series of print statements, this
sounds like a very bad idea. All the PEP proposed is a new way of
creating an anonymous generator that uses a syntax similar to that of
list comprehensions; it doesn't actually change the way generators
themselves are already handled by the language. Consider:
>>> def f():
... i, j = 0, 1
... yield i
... yield j
... while True:
... i, j = j, i + j
... yield j
...
>>> g = f() # g is now a generator
>>> print g
<generator object at 0x402e3bcc>
>>> print "%s" % g # this doesn't print the Fibonacci sequence
<generator object at 0x402e3bcc>
What you're suggesting would grievously sacrifice consistency at the
expense of a tiny little bit of convenience. It isn't worth it.
--
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ You and I / We've seen it all / Chasing our hearts' desire
\__/ The Russian and Florence, _Chess_
More information about the Python-list
mailing list