problem with exec and locals()

rocksportrocker rocksportrocker at googlemail.com
Tue Jul 1 06:56:25 EDT 2008


Hi,

the following code does not work until I ommit the "a=0" statement.


   def test():
       exec "a=3" in locals()
       print a
       a=0

    test()

print raises:
     UnboundLocalError: local variable 'a' referenced before
assignment

Can anybody explain what is going wrong here ?

Greetings, Uwe



More information about the Python-list mailing list