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

标签 python sqlalchemy pyramid configparser

我需要读取 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/

相关文章:

Python:有效计算字典列表中键的唯一值的数量

python - 调用 super() 时,元类如何与 MRO 列表一起工作?

python - SQLAlchemy - 当 count() 说还有更多结果时只返回一个结果

python - 在渲染模板时如何引用 sqlalchemy 中的自定义字段?

python - 在 Pyramid web 框架中,如何将敏感设置从外部文件导入 development.ini/production.ini?

python - 从 txt 文件中检索新行分隔符的值

python - 在 Spark 中将简单的单行字符串转换为 RDD

python - SQLAlchemy 过滤器 in_ 运算符

python - SQLAlchemy ORM - 将两个类属性添加到单个表

jquery-mobile - jquery mobile js include 正在覆盖 bootstrap css - 我该如何修复?