Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.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.025 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'assign': 0.07; 'variable,': 0.07; 'python': 0.09; 'yet.': 0.13; 'value.': 0.15; 'closures': 0.16; 'declaration,': 0.16; 'oct': 0.16; 'simpson': 0.16; 'wrote:': 0.17; 'obviously': 0.18; 'variable': 0.20; 'error.': 0.21; 'header:In-Reply-To:1': 0.25; 'message- id:@mail.gmail.com': 0.27; 'thinks': 0.29; 'included': 0.29; "i'm": 0.29; "skip:' 10": 0.30; 'received:209.85.215.46': 0.30; 'point': 0.31; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'pm,': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'but': 0.36; 'subject:with': 0.36; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'skip:u 10': 0.60; 'free': 0.61; 'subject:...': 0.63; 'here': 0.65; 'locals': 0.84; 'to:name:python': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=khm7NcQgq3qX5KZmIfljscwZYp84AS1wzBZPkV8FNcU=; b=xu7rYs/iXtxJBwSKYBuZsNCYW36hIjdqZc83U1mKCH1uuaTocH2Ky478keQex25EHj 0I9pplFeA8xbQIrpxWsQTVdNzo/d3A4PGnTD1CkClGBVEBHNU2xysBePz7ArRQjuEKry C92CqqygLr8Ify2wYKvASVDk3L8fdGyI91CuG0n7AKrvprdd5h2sQBW4E7AgB7EQQRNp 1VZimVFFIkLveGP9LnIZZHJcZfkr8m9cBoo6zeD/ZKkp3ZOGX7B28+HeSUZaegvPG5dG SDPqbI+W8gvuMs3/80/m0l0eFrIdJuHNfbfh6NGDqBArfegKKAg48tw0dD7Cnrm3eO+V 9eNA== MIME-Version: 1.0 In-Reply-To: <20121014215402.GA21565@cskk.homeip.net> References: <20121014215402.GA21565@cskk.homeip.net> From: Ian Kelly Date: Sun, 14 Oct 2012 18:32:01 -0600 Subject: Re: trouble with nested closures: one of my variables is missing... To: Python Content-Type: text/plain; charset=ISO-8859-1 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: 12 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1350261154 news.xs4all.nl 6976 [2001:888:2000:d::a6]:55155 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:31269 On Sun, Oct 14, 2012 at 3:54 PM, Cameron Simpson wrote: > | You assign to it, but there's no nonlocal declaration, so Python thinks > | it's a local var, hence your error. > > But 'unset_object' is in locals(). Why one and not the other? > Obviously there's something about closures here I'm missing. 'unset_object' is in locals because it's a free variable and those are included in locals(), and it has a value. 'attr_name' is not in locals because while it's a local variable, it has not been assigned to yet. It has no value and an attempt to reference it at that point would result in an UnboundLocalError.