加载配置文件并使用点式语法访问它们
项目描述
Thumos 配置器
一个简单的 Python3 类,使用点样式语法促进轻松加载和访问配置设置,支持 Yaml、JSON、TOML 和 XML。为了澄清,点样式语法指的是如下内容:
示例 YAML 文件:
configuration:
mysql:
host: localhost
port: 3600
使用 Configr,可以通过以下方式访问这些值:
from configr import Configr
cr = Configr("config.yaml")
cr["configuration.mysql.host"]
>> localhost
cr["configuration.mysql.port"]
>> 3600
您可能会问为什么要使用它而不是简单地使用字典。答案是; 为什么不?也许它更方便,更吸引人,或者你甚至来自 Spring Boot 之类的东西,这是它通常的完成方式。
但是,点以外的其他字符也可以用作分隔符。
cr = Configr("config.yaml", separator="/")
cr["configuration/mysql/host"]
>> localhost
还可以设置初始根密钥,以在使用可能包含与您正在处理的脚本或应用程序无关的设置的深层配置文件时最大限度地减少冗长。以以下示例 YAML 文件为例:
this:
is:
nothingInteresting: Jimmy With A Law Degree Is Like A Chimp With A Machine Gun.
really:
fantastically:
deep: Is it not?
absolutely:
annoying: Indeed
cr = Configr("config.yaml", root_key="this.is.really")
cr["fantastically.deep"]
>> Is it not?
cr["absolutely.annoying"]
>> Indeed
安装
pip install thumos-configr
像这样导入:
from configr import Configr
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。
源分布
thumos-configr-0.0.5.tar.gz
(14.8 kB
查看哈希)
内置分布
thumos_configr-0.0.5-py3-none-any.whl
(15.0 kB
查看哈希)
关
thumos_configr -0.0.5-py3-none-any.whl 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | 67ca3d9fc5c7c51eb0ca6412ff141cd2c720666c60b74ea813bc373b15d0c63b |
|
| MD5 | c47c4556ae74f2409fd4fba725654de3 |
|
| 布莱克2-256 | 7f3020371ddc3899cfd9ba23093bcbd313f53d193794e30607a10f2c63fb89cd |