蟒蛇构造

ConfigIt的Python项目详细描述


https://secure.travis-ci.org/pictage/ConfigIt.png?branch=develop

configit是mit授权的python配置库 在镜头前害羞的人。

python是关于dicts的,所以我们为什么要满足于INIs

功能

所有配置文件都是本地python文件。

使用configit,您可以将这些文件作为模块或文件读取 并返回具有属性访问权限的字典。

configit最强大的功能之一是它能够使用其他 配置中的配置。

安装

要安装configit,只需:

$ pip install configit

API文档

configit.conf_from_file(文件路径)
读取字符串文件路径并返回configdict。
filepath = r'tests/configs/default.py'

config = conf_from_file(filepath)
assert config.config_dict.name == 'default'
configit.conf_from_module(module)
读取导入的模块并返回configdict。
import tests.configs.module_config

config = conf_from_module(tests.configs.module_config)
assert config.config_dict.name == 'module_config'
configit.conf_from_dict(conf_dict)

读取字典并返回configdict。

configdict可通过属性和键访问。

config = dict(answer=42)

config = configit.conf_from_dict(config)
assert config.answer == 42
配置。使用(配置源)

在一个python配置中,您可以导入另一个python配置。 导入的配置将更新导入配置的本地名称空间。 这意味着可以在本地配置中访问子配置中的值。

这对于只需要更改一些项的锅炉板配置非常有用。

file_supplement.py contents:

answer=42

file.py contents:

import configit
configit.use('file_supplement.py')

Code using configit to get the configuration:

import configit
config = conf_from_file('file.py')

assert config.answer == 42

订单很重要!

file_supplement.py contents:

answer=42

file.py contents:

import configit
configit.use('file_supplement.py')
answer=5

Code using configit to get the configuration:

import configit
config = conf_from_file('file.py')

assert config.answer == 5

有关更多示例,请参阅包含的测试。

贡献

  1. 在github上分叉the repository,开始对development分支(或其分支)进行更改。

  2. 通过运行:

    $ python setup.py develop
    
  3. 哈克顿,舞会!

  4. 编写一个测试,显示错误已修复或功能按预期工作。

  5. 运行测试:

    $ python setup.py test
    
  6. 发送一个pull请求并对维护程序进行bug操作,直到它被合并并发布。:)请确保将自己添加到AUTHORS

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
Android Java在活动之间传递值   java当实体中存在关系时,我可以只使用实体的id而不是从DB中获取实体吗?   bouncycastle Java运行SSHD服务器错误未找到类定义   java SWT/Swing>Threads n'Hell   java多线程数据库读取   java如何在Eclipse中轻松提交Git   java在哪里可以找到字符串相等比较的一组特定排序规则?   无连接表的java单向单域关系   java扩展三角文件   java spring。杰克逊。序列化。failonemptybeans   java无法加载请求的类:oracle。jdbc。驾驶员OracleDriver   java通过数组进行索引循环并打印出元素?   找不到eclipse错误类中的java提交Hadoop作业   Java:随机设定种子   java片段、异步任务和侦听器   java在分号后使用{}