[Python-ideas] Revised^4 PEP on yield-from

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Feb 20 01:24:32 CET 2009

Antoine Pitrou wrote:

> Greg, I find this qualification ("obfuscation") a bit offensive...

Sorry, I don't mean that personally. The fact is that it
does look obfuscated to my eyes, and I'd be surprised
if I were the only person who thinks so.

> (and, actually, I don't understand how "yield from" helps for a depth-first
> traversal. Could you post an example of it?)

Traversing a binary tree with a non-generator:

   def traverse(node):
     if node:

Traversing it with a generator:

   def traverse(node):
     if node:
       yield process_node(node)
       yield from traverse(node.left)
       yield from traverse(node.right)

Do you still think an unrolled version would be
equally clear? If so, you have extremely different
tastes from me!


More information about the Python-ideas mailing list