Question on nested scope

XiaoQin Xia XQ.Xia at ccsr.cam.ac.uk
Fri Jul 13 05:33:39 EDT 2001


In Python 2.1:

>>> b=10
>>> a="b=b+11"
>>> def f(p):
        exec p
        print a
        print b

        
>>> f(a)
b=b+11
21
>>> b
10
>>> 

When exec "b=b+11", python can find the second b (10), why it generate
another b?

Cheers,
Xiao-Qin Xia



More information about the Python-list mailing list