A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2011-February/108394.html below:

[Python-Dev] Unbinding a name referenced by an enclosing scope

[Python-Dev] Unbinding a name referenced by an enclosing scope - error in documentation? [Python-Dev] Unbinding a name referenced by an enclosing scope - error in documentation?Grigory Javadyan grigory.javadyan at gmail.com
Sat Feb 26 22:23:16 CET 2011
Hi, guys
I'm not sure if python-dev is the right place to write to, but I'm
really curious about this:

>From the Python Language reference:
> It is illegal to unbind a name referenced by an enclosing scope; the compiler will report a SyntaxError.

But when I run the following code:

a = 3
def x():
 global a
 del(a)

print(a)
x()

it works fine; and when I change the order of calls:

x()
print(a)

I get a NameError, not a SyntaxError.

Now I asked the same question on python-list and people suggested that
the true meaning of that rule is:

>>> def f():
...     a = 42
...     def g():
...             nonlocal a
...             del a
...
SyntaxError: can not delete variable 'a' referenced in nested scope

Which looks weird, because the name is referenced in the _enclosed_
scope, not the _enclosing_ scope. Is there a typo in the documentation
or am I missing something?
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4