我需要读取 Python 中的 ini 配置文件,development.ini 相关部分的相关示例如下:
[app:main]
use = egg:ePRO
pyramid.reload_templates = true
pyramid.debug_authorization = false
pyramid.debug_notfound = true
pyramid.debug_routematch = true
pyramid.debug_templates = true
sqlalchemy.url = postgres://scott:tiger@localhost:5432/db
我正在使用 ConfigParser
模块读取文件,但无法从 INI 文件中读取 sqlalchemy.url
参数,
config = ConfigParser.ConfigParser()
config.read(config_uri)
如何从 [app:main]
中读取 sqlalchemy.url
参数?
最佳答案
作为the documentation shows , 在你的 config
对象上使用 get
方法
url = config.get('app:main', 'sqlalchemy.url')
关于Python 和 Pyramid - 使用 configparser 在 python 中读取 ini 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20910661/