I would like to get ConfigParser working for what seems to be a simple problem but I have an ancient 2.2 Jython system (that cannot be updated).
I would like to loop through the sections in my config file and use the same operation on its values. The first section reads fine but on the second iteration of the loop I am getting "exceptions.AttributeError".
[DEFAULT]
uHome=/opt/app/myapp/configs
[Domains]
DomainList=Dom1,Dom2
[Dom1]
userconfigFile=idm-JIT.config
userkeyFile=idm-JIT.key
admU=http://idmap01xj:7001
[Dom2]
userconfigFile=iam-JIT.config
userkeyFile=iam-JIT.key
admU=http://idmap01xjvip:7003
My (greatly) Simplified script:
import ConfigParser
config = ConfigParser.ConfigParser()
try:
config.optionxform = str
config.read(domainConfigFile);
domainList = config.get("Domains","DomainList")
domainNames = domainList.split(",")
for dName in domainNames:
UCF = config.get(dName,"uHome") + '/'+config.get(dName,"userConfigFile")
UKF = config.get(dName,"uHome") + '/'+config.get(dName,"userKeyFile")
admU = config.get(dName,"admU")
print "UCF=["+UCF+"] UKF=["+UKF+"] admU=["+admU+"]"
except:
print "Error occurred"
I'm not very fluent in Python yet (but this problem is making me so). I have been researching similar problems and playing with some snippets that modify the dict, and they work in a stock Python 2.6 interpreter but they all fail miserably in Jython 2.2.6. How can I fake the same key names in different sections so that they are all addressable?