I am having trouble changing static variable of a class instead of just an instance.
Here is my code :
class GetAbsPath():
config = RawConfigParser()
config.read('config.ini')
absPath = config['CSVPath']['Directory']
def __init__(self):
pass
def getPath(cls):
if cls.absPath.endswith('/'):
pass
else:
cls.absPath += '/'
return cls.absPath
def setPath(cls, pathStr):
cls.absPath = pathStr
In another class, I would have:
GetAbsPath.absPath = "some/other/path"
Therefore, I would want to change absPath variable in a way that absPath is permanently changed so that any other class getting the absPath would get"some/other/path"
Right now, absPathwould always be the default value everytime I call GetAbsPath.getPath().
clsargument?setPathwill replaceabsPathonly for the current instance, after which it won't "see" changes to the class attribute. Should that be a class method?getPathandsetPathsupposed to be class methods? They're not; they're instance methods, andclsis going to be just a funny name forself. Also, why do you have class variables for this? You're making a class just to manage one string global variable.