On eval and its substitution of globals

Paddy paddy3118 at netscape.net
Wed Feb 23 19:17:51 EST 2005


Leif wrote:
" If globals were deeply substituted when using eval, the program would
presumably print "42\n24", which would be far from intuitive. If you
limit the deep substitution to functions in the same module, you're
creating a confusing special case.  "

I guess I need outside opinions on what should be normal. The
documentation does not mention the case of 'nested' function calls and
so the present action could be documented but  there is still the issue
of "should there be a 'deep'  globals substitution". I have such a
need, but this is the first time I have had to consider this whole
topic.
I do in fact have the case you mention. I am writing a module that will
manipulate functions of global variables where the functions are
defined in another module.
My module will evaluate those 'other module' functions supplying the
globals itself - which works fine, the problem comes when I create
derivative functions in my module that call the original 'other module'
functions, and then try and evaluate these derivatives supplying the
globals as before. The 'correct' action that I want is for the globals
I supply to eval to be used for all functions called by the code block
as well as for the code block itself.

- Pad.




More information about the Python-list mailing list