Python和Pyramid - 使用configparser在python中读取ini文件

use*_*619 2 python sqlalchemy configparser pyramid

我需要在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
Run Code Online (Sandbox Code Playgroud)

我正在使用该ConfigParser模块读取文件,但无法sqlalchemy.url从INI文件中读取参数,

config = ConfigParser.ConfigParser()
config.read(config_uri)
Run Code Online (Sandbox Code Playgroud)

如何sqlalchemy.url从中读取参数[app:main]

Chr*_*ris 5

文档所示,请getconfig对象上使用该方法

url = config.get('app:main', 'sqlalchemy.url')
Run Code Online (Sandbox Code Playgroud)