why is this not working? (nested scope question)

bryanjugglercryptographer at yahoo.com bryanjugglercryptographer at yahoo.com
Wed Jul 26 16:14:09 EDT 2006


biner.sebastien at ouranos.ca wrote:
[...]
> def f1() :
>     x=88
>     f2()
> def f2() :
>     print 'x=',x
> f1()
>
> that returns an error saying that "NameError: global name 'x' is not
> defined". I expected f2 to "see" the value of x defined in f1 since it
> is nested at runtime.

Ah, no, Python uses "static scoping". Google the term for more.


-- 
--Bryan




More information about the Python-list mailing list