I have a semi-large python app that runs on linux. I am trying to set it up so that i can read a config file at program startup and then save those values for use at any time while the application is running, without re-reading the config file.
So I am trying to load a configValues class in my first modual, test.py. And read the values set. Then in this example read the values again in test2.py.
I never get the values. Can someone help me?
Config.py
class config():
def __init__(self):
configFile = File(myPath)
if configFile.exist():
myXML = str(configFile.openAndRead())
def setupValues(self):
configValues.color = self.getElement('color')
def getElement(self, element):
tree=et.fromstring(self.myXML)
for el in tree.findall('head'):
for ch in el.findall(element):
return ch.text
class configValues():
def __init__(self):
global color
test.py
import config
class test():
def __init__(self):
configObj = config.Config()
configVal = config.configValues()
configObj.setupValues()
print configVal.color
test2.py
import config
class test2():
def __init__(self):
configVal = config.configValues()
print configVal.color