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


Groups > comp.lang.python > #72943 > unrolled thread

Re: How to use imported function to get current globals

Started byChris Angelico <rosuav@gmail.com>
First post2014-06-08 10:37 +1000
Last post2014-06-08 10:37 +1000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: How to use imported function to get current globals Chris Angelico <rosuav@gmail.com> - 2014-06-08 10:37 +1000

#72943 — Re: How to use imported function to get current globals

FromChris Angelico <rosuav@gmail.com>
Date2014-06-08 10:37 +1000
SubjectRe: How to use imported function to get current globals
Message-ID<mailman.10870.1402187886.18130.python-list@python.org>
On Sun, Jun 8, 2014 at 10:28 AM, 1989lzhh <1989lzhh@gmail.com> wrote:
>
>
> 发自我的 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!

Frankly, no. I don't want to encourage implicitly exposing something
like that! Why do you want that, rather than something explicit and
clear?

ChrisA

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web