Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #31269

Re: trouble with nested closures: one of my variables is missing...

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 <ian.g.kelly@gmail.com>
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 <CAMZYqRRyUp5oWW3Ap4RXes7yn_gCx-PGkJyfijsFtru-CLcEww@mail.gmail.com> <20121014215402.GA21565@cskk.homeip.net>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Sun, 14 Oct 2012 18:32:01 -0600
Subject Re: trouble with nested closures: one of my variables is missing...
To Python <python-list@python.org>
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 <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2186.1350261154.27098.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Sun, Oct 14, 2012 at 3:54 PM, Cameron Simpson <cs@zip.com.au> 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.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: trouble with nested closures: one of my variables is missing... Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-14 18:32 -0600

csiph-web