New submission from john zeng <o...@163.com>:

Can you help me understand why variable `u' is not accessible after 
exec()? Is this sort of a late binding issue?

def test(v1):
    print(v1)
    print("Before exec(): " + str(locals()))
    exec(v1)
    print("After  exec(): " + str(locals()))
#   This fails:
#    print(u)
#   This is workaround:
    en = locals()['u']
    print(en)

v1="u=4"
test(v1)

----------
components: Interpreter Core
messages: 92409
nosy: ooev
severity: normal
status: open
title: exec(), locals() and local variable access
type: behavior
versions: Python 3.1

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue6862>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to