I'm trying to access a class method from the class variable as follows:
class A():
a = A.b()
@classmethod
def b():
return 5
print A.a
but i get the error:
NameError: name 'A' is not defined
What am I doing wrong?
You're using A within A. You should, first of all, put all of your initialization in an __init__ definition. And then use self to call upon itself.
class A():
def __init__ (self):
self.a = self.b()
@classmethod
def b(cls):
return 5
print A().a