python如何解析config文件

For example:
import ConfigParser
config = ConfigParser.ConfigParser()
config.read('example.cfg')

# Set the third, optional argument of get to 1 if you wish to use raw mode.
print config.get('Section1', 'foo', 0) # -> "Python is fun!"
print config.get('Section1', 'foo', 1) # -> "%(bar)s is %(baz)s!"

# The optional fourth argument is a dict with members that will take
# precedence in interpolation.
print config.get('Section1', 'foo', 0, {'bar': 'Documentation', 'baz': 'evil'})

版权声明:本文为mei_mei原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。