Recursion of function defined within another function

Stephan Tolksdorf andorxor at gmx.de
Thu Nov 9 14:23:19 EST 2000


Hello,

Why does the following program raises this error:

---Error---

Traceback (most recent call last):
  File "D:\projects\python\xrtt\test.py", line 9, in ?
    print Recur()
  File "D:\projects\python\xrtt\test.py", line 7, in Recur
    return inner(0)
  File "D:\projects\python\xrtt\test.py", line 4, in inner
    if i < 100: return inner(i)
NameError: There is no variable named 'inner'

---Source---

def Recur():
    def inner(i):
        i = i + 1
        if i < 100: return inner(i)
        else: return i 
                        
    return inner(0)

print Recur()

---

Best regards,
  Stephan Tolksdorf






More information about the Python-list mailing list