我想使用配置解析器从一个部分获取所有值
我用过这个,但它只给出了第一个值
def ConfigSectionMap(section):
dict1 = {}
options = Config.options(section)
for option in options:
try:
dict1[option] = Config.get(section, option)
if dict1[option] == -1:
DebugPrint("skip: %s" % option)
except:
print("exception on %s!" % option)
dict1[option] = None
return dict1
Config = ConfigParser.ConfigParser()
Config.read("/etc/harvest.conf")
print ConfigSectionMap("files").values()
把它作为一个词典:
dict(Config.items('Section'))
如果订购很重要,您可以将其列为清单
list(Config.items('Section'))