ConfigParser with multiple sections and the same option names?
I'd like ConfigParser to work on what seems like a simple problem, but I have an old 2.2 Jython system (which 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 get an "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 (significantly) 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 sure about Python yet (but this problem makes me so). I am looking into similar problems and playing around with some snippets that modify the dict and they work in the Python 2.6 interpreter, but they all fail in Jython 2.2.6. How can I spoof the same key names in different sections so that they are addressed?
source to share
No one has answered this question yet
Check out similar questions: