D
David
Hi all,
I'm trying to understand how scopes work within a class definition.
I'll quickly illustrate with an example. Say I had the following class
definition:
class Abc:
message = 'Hello World'
def print_message(self):
print message
NameError: global name 'message' not defined
My question is, why? message is not defined in print_message, but it
is defined in the enclosing scope (the class)?
Thanks!
I'm trying to understand how scopes work within a class definition.
I'll quickly illustrate with an example. Say I had the following class
definition:
class Abc:
message = 'Hello World'
def print_message(self):
print message
NameError: global name 'message' not defined
My question is, why? message is not defined in print_message, but it
is defined in the enclosing scope (the class)?
Thanks!