[New-bugs-announce] [issue3963] Problems when calling exec from a function

Erik Sandberg report at bugs.python.org
Thu Sep 25 17:10:21 CEST 2008


New submission from Erik Sandberg <sandberg at virtutech.com>:

When an exec statement called from a function f defines a top-level
function g, the body of g cannot access the top-level symbols defined by
the exec statement (which also happen to be the local variables of f).
Example:

x = 2
def f():
    exec "x = 1\ndef b(): return x"
    print b()
f()

An unqualified guess is that the mix of being top-level and being a
local variable, makes the symbol end up somewhere between locals() and
globals(). Example:

The problem causes real-life problems when I want to create a wrapper
function around execfile() to handle certain exceptions.

----------
components: Interpreter Core
messages: 73795
nosy: sandberg
severity: normal
status: open
title: Problems when calling exec from a function
type: behavior
versions: Python 2.4, Python 2.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3963>
_______________________________________


More information about the New-bugs-announce mailing list