小编Mat*_*ini的帖子

使用 python 的带有字典的配置文件

因此,我尝试在配置文件中使用字典来将报告名称存储到 API 调用中。所以像这样:

report = {'/report1': '/https://apicall...', '/report2': '/https://apicall...'}
Run Code Online (Sandbox Code Playgroud)

我需要存储多个报告:对一个配置值的 API 调用。我正在使用 ConfigObj。我读过那里的文档文档说我应该能够做到。我的代码看起来像这样:

from configobj import ConfigObj
config = ConfigObj('settings.ini', unrepr=True)
for x in config['report']:
    # do something... 
    print x
Run Code Online (Sandbox Code Playgroud)

然而,当它到达 config= 时,它会抛出一个引发错误。我有点迷失在这里。我什至复制并粘贴了他们的示例和相同的内容“引发错误”。我正在使用 python27 并安装了 configobj 库。

python dictionary config python-2.7 configobj

3
推荐指数
1
解决办法
3万
查看次数

标签 统计

config ×1

configobj ×1

dictionary ×1

python ×1

python-2.7 ×1