This code works in the python command line. However, when compiling it in a module it gives the following error: "name 'A' is not defined."
>>> class A:
... a = 2
... c = A.a
...
>>> A.c
2
class A:
a = 2
c = A.a
NameError: name 'A' is not defined
I found a better solution. As shown below, a static variable is available for the initialization of another static variable. The code below compiles fine.
class A:
a = 2
b = a
c = A()
print(c.b)
Aisn't defined until after theclassblock is finished. So you can't reference it while defining the class.Aclass. So you were using the old value ofA.a.