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


Groups > comp.lang.python > #72943

Re: How to use imported function to get current globals

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.019
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'cpython': 0.05; 'explicit': 0.07; 'subject:How': 0.10; 'cc:addr:python-list': 0.11; 'def': 0.12; '8bit%:32': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; "module's": 0.16; 'wrote:': 0.18; 'module': 0.19; '>>>': 0.22; 'example': 0.22; 'import': 0.22; '(in': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'certainly': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'am,': 0.29; 'said,': 0.30; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'this.': 0.32; 'thanks!': 0.32; 'could': 0.34; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'that!': 0.36; 'rather': 0.38; 'that,': 0.38; 'how': 0.40; 'ian': 0.60; 'no.': 0.61; 'iphone': 0.65; 'here': 0.66; 'subject:get': 0.81; 'expose': 0.84; 'exposing': 0.91; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type:content-transfer-encoding; bh=7lyrE0c6kTndWfYgCNNUPsrHVe2bKAPG6sh7keYVwPA=; b=w7MFhPGMA0mESMSpL/P7IEU1VNKhU3yR0GgRNiNjQlGtuEHklELBKxdtv6hn43sySv y+cUfSmddDv0ToxnfM4/uvGE3hf1Ei4jpRdZSD6KykCQH/3r9daqZNQCbkuR+rKMxebo 9QRXMhwGigfOWtKdp4a49Cky104B63gl4U4T6SfbIe5VbbELaKeg+/iBa5eIDs9dEUii vNNlr60vqUx7yAJaS+WPpNsmm77S+yRDNv+9tzyLCh6y4Hkzgs1Q44WBDOJMzIZjyng4 X/ekEsQ6IVyyOlB4+xlSY1+X4szM5R4XDkR44qHg1mEro5R6OEypZudObrzTuju+N77Z 8JpQ==
MIME-Version 1.0
X-Received by 10.220.69.72 with SMTP id y8mr15998244vci.21.1402187878187; Sat, 07 Jun 2014 17:37:58 -0700 (PDT)
In-Reply-To <510F7020-C682-4A4B-B3ED-5D289D17C5DE@gmail.com>
References <602B90F0-E7FE-4887-ADA1-981FD4179EC7@gmail.com> <CAPTjJmq8w55crQc4zh_=aEF54POryudsr-0WLkMf_AU5-L-ByA@mail.gmail.com> <510F7020-C682-4A4B-B3ED-5D289D17C5DE@gmail.com>
Date Sun, 8 Jun 2014 10:37:58 +1000
Subject Re: How to use imported function to get current globals
From Chris Angelico <rosuav@gmail.com>
Cc python_list <python-list@python.org>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.10870.1402187886.18130.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1402187886 news.xs4all.nl 2903 [2001:888:2000:d::a6]:56785
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:72943

Show key headers only | View raw


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

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


Thread

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

csiph-web