Issue1115039
Created on 2005-02-02 20:59 by carou, last changed 2005-02-02 23:26 by rhettinger.
| File name |
Uploaded |
Description |
Edit |
Remove |
|
test.py
|
carou,
2005-02-02 20:59
|
short demonstration |
|
|
|
msg24136 - (view) |
Author: Andrew Collier (carou) |
Date: 2005-02-02 20:59 |
|
python 2.3 as installed by default in MacOS X 10.3.7
This may be the same as item 991196, but that's my uneducated
guess since I don't understand the cause of either one... (in fact it
may not even really be a bug, but at the least this is behaviour I'm
unable to explain).
It seems that fewer symbols are available to eval() than are
available to literal code. The best way to describe the problem is
with the attached short example file.
In the function evalfunction2(), a call via eval() is unable to
resolve the symbol name evalfunction1 - even though it would be
possible to call evalfunction1() directly.
But if the code *does* call evalfunction1() directly, then the eval()
can see that symbol too(!).
|
|
msg24137 - (view) |
Author: Raymond Hettinger (rhettinger) |
Date: 2005-02-02 23:26 |
|
Logged In: YES
user_id=80475
Sorry, this isn't a bug. The eval() function is documented
to only search globals() and local(). The nested scope of
eval's caller is not included.
In your code, callfunction2 works because callfunction1 can
be found in the nested scope.
In contrast, evalfunction2 fails because evalfunction1 is
not in the locals() or globals(); instead, is in a enclosing
nested scope which is not searched.
The reason that evalfunction2 works if you uncomment the
extra code is the subsequent reference to evalfunction1 gets
it brought into locals() at compilation time (when the def
is executed).
For real code, is you want a nested scope object to be found
by eval, then either reference it in the same function that
calls eval() or, more explicitly, just add it to a
dictionary of things that should be visible to eval().
|
|
| Date |
User |
Action |
Args |
| 2005-02-02 20:59:30 | carou | create | |
|