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> Mime-Version: 1.0 (1.0) In-Reply-To: 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 Cc: python_list X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 =B7=A2=D7=D4=CE=D2=B5=C4 iPhone > =D4=DA Jun 8, 2014=A3=AC4:52=A3=ACChris Angelico =D0=B4= =B5=C0=A3=BA >=20 >> On Sun, Jun 8, 2014 at 3:40 AM, 1989lzhh <1989lzhh@gmail.com> wrote: >> Here is the code >> m1.py >> def f(): >> print globals() >>=20 >> m2.py >> from m1 import f >> f()# how to get current module's globals? >=20 > 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 c= an expose something into current module implicitly. Thanks! Liu zh= enhai >=20 > Normally, passing dictionaries around is going to be MUCH more useful. > (And probably not actually globals(), you almost never want to use > that.) >=20 > ChrisA > --=20 > https://mail.python.org/mailman/listinfo/python-list