Getting globals of the caller, not the defining module
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Fri Nov 15 03:23:22 EST 2013
On Thu, 14 Nov 2013 20:56:34 +0000, Rotwang wrote:
[...]
>> How about this?
>>
>> # module A.py
>> import inspect
>> def spam():
>> return inspect.stack()[1][0].f_globals
>
> Bump. Did this do what you wanted, or not?
Sort of. If anything, it convinced me that I don't, in fact, want what I
thought I wanted.
I'm still playing around with the code, but it's looking likely that auto-
detecting the caller's globals is not really what I want.
--
Steven
More information about the Python-list
mailing list