Message24415
Logged In: YES
user_id=1230541
I think this issue is not special for eval and can be also
reproduced with a def statement. The point is that at function
definition time Python does not do any variable binding
concerning variables not local to the function. Instead Python
looks for that variable in the namespace of the module in
which the function was created at the time the function is
executed. Python determines that module by evaluating the
variable __module__ at function definition time and
remembers it by setting the function attribute with the same
name. That's why only the variable __module__ is relevant at
function definition time. Simply put, Python does only do a
module level variable binding at function definition time. This
is simple and sensible. If you don't agree consider this:
n=2
def f(x): return n*x
del n
f(2)
# the Python implementation will result in a name error here.
But what should happen if Python had bound variable n at the
time of f's definitionf?
# let's define n again
f(2)
# the implementation will return 6, but how about your
expected implementation?
As you see, changing the implementation would either make
Pythons semantics more complicated or would remove much
of Pythons dynanism.
|
|
Date |
User |
Action |
Args |
2007-08-23 14:29:50 | admin | link | issue1153622 messages |
2007-08-23 14:29:50 | admin | create | |
|