27
我想用配置解析器Python配置解析器獲取節中的所有值?
我用這個來從一節中的所有值,但它僅給出了第一個值
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()
您的'返回'不正確nted,你的函數在for循環的第一次迭代中返回。刪除兩個空格。 – Chewie 2011-12-20 16:27:02