【发布时间】:2017-06-06 16:00:17
【问题描述】:
Documentation 有一个范例,其中唯一的部分称为 settings 这似乎是 python-decouple 的默认命名空间,因此如果你有:
[settings]
DEBUG=True
您可以使用以下方式解析配置:
from decouple import config
DEBUG = config('DEBUG', default=False, cast=bool) # no section argument
但是如果我们有自定义部分,例如:
[sectionA]
DEBUG=True
[sectionB]
foo="bar"
?
我知道可以轻松地使用 ConfigParser 来解析自定义部分,如下所示:
config_parser.get('sectionA', 'DEBUG') # the corresponding call in ConfigParser
但我想知道它是如何通过 python-decouple 完成的,因为它还支持 .ini 文件
【问题讨论】:
标签: python-3.x ini decoupling python-decouple