P
Paddy
Hi,
I got tripped up on the way eval works with respect to modules and
so wrote a test.
It seems that a function carries around knowledge of the globals()
present
when it was defined. (The .func_globals attribute)?
When evaluated using eval(...) the embedded globals can be overridden
with
the one passed through the eval(...) call
If however you create a new function that calls the first then eval's
global argument is only substituted in the outer call!
TEST:
=====
Python 2.4 (#2, Jan 8 2005, 20:18:03)
[GCC 3.3.5 (Debian 1:3.3.5-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 1, in z
ENDTEST
=======
Is there a way to do a deep substitution of the globals?
I should add that f1 is given as-is. I can modify z,
and f1 is just one of many functions given and function z
is some boolean function of the f<n>'s
Thanks, Pad.
I got tripped up on the way eval works with respect to modules and
so wrote a test.
It seems that a function carries around knowledge of the globals()
present
when it was defined. (The .func_globals attribute)?
When evaluated using eval(...) the embedded globals can be overridden
with
the one passed through the eval(...) call
If however you create a new function that calls the first then eval's
global argument is only substituted in the outer call!
TEST:
=====
Python 2.4 (#2, Jan 8 2005, 20:18:03)
[GCC 3.3.5 (Debian 1:3.3.5-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 1, in z
ENDTEST
=======
Is there a way to do a deep substitution of the globals?
I should add that f1 is given as-is. I can modify z,
and f1 is just one of many functions given and function z
is some boolean function of the f<n>'s
Thanks, Pad.