There are plenty answers for how to access static variables from static methods (like this one, and that one, and the great info on the subject here), however I'm having trouble with the other direction: How can you use static methods to initialize static variables. E.g.:
import os, platform
class A(object):
@staticmethod
def getRoot():
return 'C:\\' if platform.system() == 'Windows' else '/'
pth = os.path.join(A.getRoot(), 'some', 'path')
The last line gives an exception: NameError: name 'A' is not defined
. The same error happens if I use @classmethod
instead of @staticmethod
.
Is it possible to access a static method from a class variable?