L
Learning Python
A example in learning Python by Mark Lutz and David Ascher
about function scope
example like this:
def inner(i):
print i,
if i: inner(i-1)
inner(x)
Here supposely, it should report error, because the function inner
cannot see itself since inner is only in local namespace of outer.
but I typed in this in python interface. It works!
it print out:
3 2 1 0
If you turn this into a module file and run this
it print out
3 2 1 0 none
Can anyone explain to me what's going on?
Thanks
BTW: I am using Python 2.3
about function scope
example like this:
def inner(i):
print i,
if i: inner(i-1)
inner(x)
Here supposely, it should report error, because the function inner
cannot see itself since inner is only in local namespace of outer.
but I typed in this in python interface. It works!
it print out:
3 2 1 0
If you turn this into a module file and run this
it print out
3 2 1 0 none
Can anyone explain to me what's going on?
Thanks
BTW: I am using Python 2.3