Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'exception': 0.03; '[1]:': 0.09; '[2]:': 0.09; 'effect.': 0.09; 'nameerror:': 0.09; 'def': 0.10; '#this': 0.16; "isn't.": 0.16; 'scope.': 0.16; 'wrote:': 0.17; '>>>': 0.18; '"",': 0.22; 'modifying': 0.22; 'defined': 0.22; 'this:': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; '(most': 0.27; 'dictionary': 0.29; 'case,': 0.29; 'no,': 0.29; 'returned': 0.30; 'stuff': 0.30; 'file': 0.32; 'print': 0.32; 'traceback': 0.33; 'to:addr:python-list': 0.33; 'pm,': 0.35; 'subject:?': 0.35; 'there': 0.35; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'received:62': 0.62; 'email addr:gmail.com': 0.63; 'wired': 0.65; 'subject:this': 0.84; 'from:addr:t': 0.84; 'received:62.75': 0.84 Date: Tue, 18 Sep 2012 23:51:13 +0200 From: Thomas Jollans User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120827 Thunderbird/15.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: User defined lexical scoping... can I do this? References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348005076 news.xs4all.nl 6857 [2001:888:2000:d::a6]:55427 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:29453 On 09/18/2012 10:50 PM, weissman.mark@gmail.com wrote: > Well there's wired stuff like this: > > In [1]: locals()["x"] = 5 > > In [2]: print x > 5 > No, there isn't. Modifying the dictionary returned by locals() has no effect. >>> def f (): ... locals()["x"] = 1 ... return x ... >>> f () Traceback (most recent call last): File "", line 1, in File "", line 3, in f NameError: global name 'x' is not defined >>> >>> locals()["x"] = 1 >>> x 1 >>> #this works because ... locals() is globals() True >>> The exception is the case when local scope is identical to global scope. In this case, locals() has globals() semantics.