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

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <1989lzhh@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.039
X-Spam-Evidence '*H*': 0.92; '*S*': 0.00; 'cpython': 0.05; 'subject:How': 0.10; 'cc:addr:python-list': 0.11; 'def': 0.12; 'dictionaries': 0.16; 'globals(),': 0.16; 'liu': 0.16; "module's": 0.16; 'normally,': 0.16; 'wrote:': 0.18; 'module': 0.19; 'passing': 0.19; '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; 'url:mailman': 0.30; 'code': 0.31; 'this.': 0.32; 'probably': 0.32; 'thanks!': 0.32; 'url:python': 0.33; 'could': 0.34; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'url:listinfo': 0.36; 'url:org': 0.36; 'message-id:@gmail.com': 0.38; 'url:mail': 0.40; 'how': 0.40; 'ian': 0.60; 'header:Message-Id:1': 0.63; 'more': 0.64; 'iphone': 0.65; 'to:addr:gmail.com': 0.65; 'here': 0.66; 'useful.': 0.68; 'charset:gb2312': 0.80; 'subject:get': 0.81; '8bit%:24': 0.84; 'expose': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=references:mime-version:in-reply-to:content-type :content-transfer-encoding:message-id:cc:from:subject:date:to; bh=zoszow1HAngWo2+6J2d525pS1meV4Y/LZFeHGm1p6N4=; b=KvSo9vK7rm7uwnlomDTfsP8/e7XOOM96XPyXvMIe8oBPYw3P+LoC282WNjIq3MFqxY h0LXOcNlGuU98PMdsaVmsJc+70UYXQgL60wekjfKT5MMam8t5rmywBPlPW9XJZb5tmse ZWiyr2ViYRToewJQTEwk/zKRUXsRL347nAHsgoWAh9NAQk9u8O39PfOh6NDInjaus7yq 4EvZkz9pkWCLNjQ2oHHNNuS9TPbLPPnCoAhkb8gqSQeJ2U28KjWCNSyHw9tuGjHUef7W jyLUHt5C+WcQvW8JumX3TNDXrF4k9kupnyxZ86gteZPdj2FA1Xck+x8qbRYgrfYzD14A 9KbA==
X-Received by 10.68.197.134 with SMTP id iu6mr141269pbc.164.1402187310527; Sat, 07 Jun 2014 17:28:30 -0700 (PDT)
References <602B90F0-E7FE-4887-ADA1-981FD4179EC7@gmail.com> <CAPTjJmq8w55crQc4zh_=aEF54POryudsr-0WLkMf_AU5-L-ByA@mail.gmail.com>
Mime-Version 1.0 (1.0)
In-Reply-To <CAPTjJmq8w55crQc4zh_=aEF54POryudsr-0WLkMf_AU5-L-ByA@mail.gmail.com>
Content-Type text/plain; charset=gb2312
Content-Transfer-Encoding quoted-printable
X-Mailer iPhone Mail (11D201)
From 1989lzhh <1989lzhh@gmail.com>
Subject Re: How to use imported function to get current globals
Date Sun, 8 Jun 2014 08:28:23 +0800
To Chris Angelico <rosuav@gmail.com>
Cc python_list <python-list@python.org>
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.10868.1402187319.18130.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1402187319 news.xs4all.nl 2911 [2001:888:2000:d::a6]:52656
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:72941

Show key headers only | 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