PEP 255: Simple Generators

Toby Dickenson tdickenson at devmail.geminidataloggers.co.uk
Tue Jun 19 04:52:14 EDT 2001


Greg Ewing <see at my.signature> wrote:

>Something is bothering me about this. In fact,
>it's bothering me a LOT. In the following, will
>f() work as a generator-function:
>
>  def f():
>    for i in range(5):
>      g(i)
>
>  def g(i):
>    for j in range(10):
>      yield i,j
>
>If I understand PEP255 correctly, this will *not*
>work. But it seems entirely reasonable to me that
>it *should* work. It *has* to work, otherwise how
>am I to write generators that are too complicated
>to fit into a single function?
>
>Someone please tell me I'm wrong about this!
 
  def f():
    for i in range(5):
      for pair in g(i):
        yield pair

  def g(i):
    for j in range(10):
      yield i,j





Toby Dickenson
tdickenson at geminidataloggers.com



More information about the Python-list mailing list