I am relatively new to Python development, and in reading through the language documentation, I came across a line that read:
It is illegal to unbind a name that is referenced by an enclosing scope; the compiler will report a SyntaxError.
So in a learning exercise, I am trying to create this error in the interactive shell, but I haven't been able to find a way to do so. I am using Python v2.7.3, so using the nonlocal keyword like
def outer():
a=5
def inner():
nonlocal a
print(a)
del a
is not an option, and without using nonlocal, when Python sees del a in the inner function, it interprets it as a local variable that has not been bound and throws an UnboundLocalError exception.
Obviously there is an exception to this rule with regards to global variables, so how can I create a situation where I am "illegally" unbinding a variable name that is being referenced by an enclosing scope?