I am wondering if it is possible to define a Python class with class variables initialized using a @classmethod
of this class. Following code fails but explains what I mean:
class foo:
a = 1
b = 2
c = foo.add(a, b) # NameError: name 'foo' is not defined
# c = a + b # <-want to achieve this, but it duplicates add(),
# which is what I want to avoid
@classmethod
def add(cls, x, y):
return x+y
Also tried c = add(a, b)
but got TypeError: 'classmethod' object is not callable
.
Anybody has a clue? Any advice will be appreciated.