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...

References <CAMZYqRRyUp5oWW3Ap4RXes7yn_gCx-PGkJyfijsFtru-CLcEww@mail.gmail.com> <20121014215402.GA21565@cskk.homeip.net>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2012-10-14 18:32 -0600
Subject Re: trouble with nested closures: one of my variables is missing...
Newsgroups comp.lang.python
Message-ID <mailman.2186.1350261154.27098.python-list@python.org> (permalink)

Show all headers | 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