baffled classes within a function namespace. Evaluation order.
Alastair Thompson
hexforge at gmail.com
Thu Apr 25 18:37:53 EDT 2013
Thats a good pointer to what is going on. Thank you Bas.
I am familiar with error such as
x=1
def foo():
x = 2
def erm():
print(x)
x=3
erm()
foo()
UnboundLocalError: local variable 'x' referenced before assignment.
It seems a bit different for classes (below), as it jumps out to get the
value from the global name space, where it didn't for functions (above).
x=1
def foo():
x = 2
class erm():
print(x)
x = 3
foo() # This evaluates == 1
But you certainly have explained why "NameError: name 'third' is not
defined" occurs.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130425/3b916757/attachment.html>
More information about the Python-list
mailing list