Globals, Locals Dictionaries + Callbacks Question

Faisal Alquaddoomi falquaddoomi at
Wed Dec 21 04:46:35 EST 2005


I'm having a bit of trouble isolating my scripts from each other in my 
embedded Python interpreter, so that their global namespaces don't get 
all entangled. I've had some luck with PyRun_FileEx(), as you can 
specify dictionaries to use for the globals and locals, but it seems 
that you can't do the same for PyEval_CallObject() (which i use for 
calling the callbacks previously registered by scripts run via 
PyRun_FileEx()). Is there any way to substitute the current global/local 
dictionaries, run the callback, then switch back to the default? It 
would be just as good if I could switch between several sets of global 
variable dictionaries, one for each script; unfortunately, the 
documentation is less than informative on this point (there isn't even a 
formal defintion for PyEval_CallObject()). Also, I'm aware that eval() 
and exec() allow you to pass in global/local dictionaries, but I think 
it'd be a bit wasteful to drop into Python, run exec(), then have that 
call my callback, rather than just calling the callback directly from 
the host program.

Thanks in advance

More information about the Python-list mailing list