I have a following class:
class Foo:
CONSTANT = 1
def some_fn(self):
a = Foo.CONSTANT
# do something
How can I refer to Foo.CONSTANT without referring to Foo, or refer to Foo in a generic way? (I don’t want to change all references to it when renaming a class)
Within a method of class
Fooor any subclass thereof,self.CONSTANTwill refer to the value defined for that class attribute in classFoo(unless it’s overridden in a subclass or in the instance itself — if you assignself.CONSTANT=23, it’s the instance attribute that’s created with that value, and it overrides the class attribute in future references).