Mixing generators and recursion

Gerson Kurz gerson.kurz at t-online.de
Tue Nov 4 21:43:22 CET 2003


No, it has nothing to do with the pathname. Try this:

def f(nested):
    if not nested:
        f(True)
    else:
        yield 42
    
for k in f(False): print k

Step through it in the mind: 
- f(False) gets called
- it is not nested, so f(True) gets called
- it is nested, so should yield 42 - but it doesn't!
- instead, you get an empty list.




More information about the Python-list mailing list