Re: Getting globals of the caller, not the defining module

2013-11-15 Thread Steven D'Aprano
On Thu, 14 Nov 2013 20:56:34 +, 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

Re: Getting globals of the caller, not the defining module

2013-11-14 Thread Rotwang
On 11/11/2013 12:02, sg...@hotmail.co.uk wrote: (Sorry for posting through GG, I'm at work.) On Monday, November 11, 2013 11:25:42 AM UTC, Steven D'Aprano wrote: Suppose I have a function that needs access to globals: # module A.py def spam(): g = globals() # this gets globals from A

Re: Getting globals of the caller, not the defining module

2013-11-12 Thread Rotwang
On 12/11/2013 01:57, Terry Reedy wrote: On 11/11/2013 7:02 AM, sg...@hotmail.co.uk wrote: (Sorry for posting through GG, I'm at work.) On Monday, November 11, 2013 11:25:42 AM UTC, Steven D'Aprano wrote: Suppose I have a function that needs access to globals: # module A.py def spam(): g

Re: Getting globals of the caller, not the defining module

2013-11-11 Thread Terry Reedy
On 11/11/2013 7:02 AM, sg...@hotmail.co.uk wrote: (Sorry for posting through GG, I'm at work.) On Monday, November 11, 2013 11:25:42 AM UTC, Steven D'Aprano wrote: Suppose I have a function that needs access to globals: # module A.py def spam(): g = globals() # this gets globals from A

Re: Getting globals of the caller, not the defining module

2013-11-11 Thread sg552
(Sorry for posting through GG, I'm at work.) On Monday, November 11, 2013 11:25:42 AM UTC, Steven D'Aprano wrote: > Suppose I have a function that needs access to globals: > > # module A.py > def spam(): > g = globals() # this gets globals from A > introspect(g) > > As written, spam() o

Re: Getting globals of the caller, not the defining module

2013-11-11 Thread Chris Angelico
On Mon, Nov 11, 2013 at 10:25 PM, Steven D'Aprano wrote: > But since spam is supposed to introspect as much information as possible, > I don't really want to do that. What (if anything) are my other options? You're playing with introspection, so I'd look at poking around in the stack trace. It'll

Getting globals of the caller, not the defining module

2013-11-11 Thread Steven D'Aprano
Suppose I have a function that needs access to globals: # module A.py def spam(): g = globals() # this gets globals from A introspect(g) As written, spam() only sees its own globals, i.e. those of the module in which spam is defined. But I want spam to see the globals of the caller. #