Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'context': 0.04; 'subject:Python': 0.06; 'exec': 0.07; 'function,': 0.07; 'received:verizon.net': 0.07; 'terry': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'am,': 0.12; 'closure,': 0.16; 'executed.': 0.16; 'local.': 0.16; 'model.': 0.16; 'reedy': 0.16; 'wrote:': 0.16; 'jan': 0.19; 'header:In-Reply-To:1': 0.22; "python's": 0.24; 'stack': 0.24; 'code': 0.25; 'code.': 0.26; 'function': 0.27; 'code,': 0.28; 'right.': 0.28; 'subject:support': 0.30; 'subject:?': 0.31; 'objects': 0.32; 'to:addr:python-list': 0.33; 'header:User-Agent:1': 0.34; 'subject:/': 0.34; 'function.': 0.34; 'header:X-Complaints-To:1': 0.35; 'variables': 0.37; 'passed': 0.37; 'but': 0.37; 'received:org': 0.38; 'subject:: ': 0.39; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'locals': 0.84; 'operate.': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Python 3.X: nonlocal support in eval/exec? Date: Thu, 11 Aug 2011 03:48:28 -0400 References: <6392cd6f-5c11-4abb-91f4-5ca37baffc68@e35g2000yqc.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-74-109-121-73.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0 In-Reply-To: <6392cd6f-5c11-4abb-91f4-5ca37baffc68@e35g2000yqc.googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 17 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1313048932 news.xs4all.nl 23847 [2001:888:2000:d::a6]:41436 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:11192 On 8/11/2011 3:19 AM, Paddy wrote: > We can access nonlocal variables in a function, but if we were to eval/ > exec the function we cannot set up a nested stack of evironment dicts. > We are limited to just two: global and local. Right. That was and is Python's execution model. Note that when you exec code, including a function call, the locals passed is the local context in which the code is executed. It is not the locals of any particular function called by the exec-ed code. If you exec a function that is a closure, the closure or non-local objects come with the function. A 'stack of dicts' has nothing to do with how function and nested funcs operate. -- Terry Jan Reedy