I am trying to read a property from properties file and if it is not there, i need to add that property to properties file
Following is my script
import ConfigParser
config = ConfigParser.RawConfigParser()
config.read('test.properties')
ip = config.get('client', 'primaryIp')
print "ip is " +ip
if not ip:
Config.set('client','primaryIp','10.31.1.143')
But it throws the following error at line " ip = config.get('client', 'primaryIp') "
Traceback (most recent call last):
File "test.py", line 8, in <module>
ip = config.get('client', 'primaryIp')
File "/usr/lib64/python2.7/ConfigParser.py", line 340, in get
raise NoOptionError(option, section)
ConfigParser.NoOptionError: No option 'primaryIp' in section: 'client'
How could i avoid this exception