- :
example.conf:
[section]
a = 10
b = 15
c = %(a)s+%(b)s
d = %(b)s+%(c)s
script :
import ConfigParser
config = ConfigParser.SafeConfigParser()
config.readfp(open('example.conf'))
print config.get('section', 'a')
print config.get('section', 'b')
print config.get('section', 'c')
print config.get('section', 'd')
:
print eval(config.get('section', 'c'))
print eval(config.get('section', 'd'))
, , ConfigParser , , get() , :
def my_get(self, section, option, eval_func=None):
value = self.get(section, option)
return eval_func(value) if eval_func else value
setattr(ConfigParser.SafeConfigParser, 'my_get', my_get)
print config.my_get('section', 'c', eval)
print config.my_get('section', 'a', int)