Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #72941

Re: How to use imported function to get current globals

References <602B90F0-E7FE-4887-ADA1-981FD4179EC7@gmail.com> <CAPTjJmq8w55crQc4zh_=aEF54POryudsr-0WLkMf_AU5-L-ByA@mail.gmail.com>
From 1989lzhh <1989lzhh@gmail.com>
Subject Re: How to use imported function to get current globals
Date 2014-06-08 08:28 +0800
Newsgroups comp.lang.python
Message-ID <mailman.10868.1402187319.18130.python-list@python.org> (permalink)

Show all headers | View raw



发自我的 iPhone

> 在 Jun 8, 2014,4:52,Chris Angelico <rosuav@gmail.com> 写道:
> 
>> On Sun, Jun 8, 2014 at 3:40 AM, 1989lzhh <1989lzhh@gmail.com> wrote:
>> Here is the code
>> m1.py
>> def f():
>>    print globals()
>> 
>> m2.py
>> from m1 import f
>> f()# how to get current module's globals?
> 
> As Ian said, you almost certainly do not want to do this. But if you
> have a solid use-case that involves finding the caller's globals, you
> can do it (in CPython - no idea about other Pythons) with the
> backtrace.
   Could you give an example ? I do want to get the caller's globals, so I can expose something into current module implicitly. Thanks!
                                                                      Liu zhenhai
> 
> Normally, passing dictionaries around is going to be MUCH more useful.
> (And probably not actually globals(), you almost never want to use
> that.)
> 
> ChrisA
> -- 
> https://mail.python.org/mailman/listinfo/python-list

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: How to use imported function to get current globals 1989lzhh <1989lzhh@gmail.com> - 2014-06-08 08:28 +0800

csiph-web