[Python-Dev] yield back-and-forth?

Edward C. Jones edcjones at comcast.net
Fri Jan 20 20:51:39 CET 2006


Guido van Rossum <guido at python.org> wrote:

The discussion about PEP 343 reminds me of the following. Bram Cohen
pointed out in private email that, before PEP 342, there wasn't a big
need for a shortcut to pass control to a "sub-generator" because the
following for-loop works well enough:

 def main_generator():
      ...
      for value in sub_generator():
          yield value

This is an important programming trick. It allows recursive use of 
generators for walking trees, etc. See the source code for os.walk for 
an example.




More information about the Python-Dev mailing list