Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: baffled classes within a function namespace. Evaluation order.

Reply
Thread Tools

Re: baffled classes within a function namespace. Evaluation order.

 
 
Alastair Thompson
Guest
Posts: n/a
 
      04-25-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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
baffled classes within a function namespace. Evaluation order. Alastair Thompson Python 1 04-25-2013 10:08 PM
Baffled by this ... (casting of function pointers) Alfonso Morra C Programming 7 08-26-2005 02:35 PM
[EVALUATION] - E03 - jamLang Evaluation Case Applied to Python Ilias Lazaridis Python 2 04-24-2005 05:29 PM
[EVALUATION] - E04 - jamPersist Evaluation Case Applied to Ruby Ilias Lazaridis Ruby 18 04-09-2005 04:45 PM
[EVALUATION] - E03 - jamLang Evaluation Case Applied to Ruby Ilias Lazaridis Ruby 74 04-04-2005 05:29 PM



Advertisments