[New-bugs-announce] [issue6862] exec(), locals() and local variable access

john zeng report at bugs.python.org
Tue Sep 8 09:22:07 CEST 2009


New submission from john zeng <ooev at 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 <report at bugs.python.org>
<http://bugs.python.org/issue6862>
_______________________________________


More information about the New-bugs-announce mailing list