On Sun, Oct 14, 2012 at 3:54 PM, Cameron Simpson <c...@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.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to