【发布时间】:2011-03-14 08:03:45
【问题描述】:
通常,我编写如下代码以获取变量中的特定项目,如下所示
try:
config = ConfigParser.ConfigParser()
config.read(self.iniPathName)
except ConfigParser.MissingSectionHeaderError, e:
raise WrongIniFormatError(`e`)
try:
self.makeDB = config.get("DB","makeDB")
except ConfigParser.NoOptionError:
self.makeDB = 0
有没有办法读取python字典中的所有内容?
例如
[一种] x=1 y=2 z=3 [乙] x=1 y=2 z=3被写入
val["A"]["x"] = 1 ... val["B"]["z"] = 3【问题讨论】:
-
来自 Python 3 的 ConfigParser 具有此功能,您可以使用 backport 在 Python 2 中拥有它
标签: python configuration-files ini