读取配置文件,conf.d样式
项目描述
读取配置文件,conf.d样式
需求
- Python 2.6+ 或 Python 3.4+ 
安装
使用PIP
从Github
pip install git+git://github.com/josegonzalez/conf_d.git#egg=conf_d
从PyPI
pip install conf_d==0.1.0
用法
用法
# in your /etc/derp/conf file
[derp]
no: sleep
til: brooklyn
[herp]
sleep: 1
wait: 5.0
timeout: seventy
# From your fictional derp module
from conf_d import Configuration
def digitize(config):
    for key in config:
        if not config[key].isdigit():
            try:
                config[key] = float(config[key])
            except ValueError:
                pass
        else:
            try:
                config[key] = int(config[key])
            except ValueError:
                pass
        return config
# All defaults must be strings
conf = Configuration(
    name="derp",
    path="/etc/derp/conf",
    main_defaults={
        "no": "one",
        "expected": "the spanish inquisition",
        "cats": "1",
    },
    section_parser=digitize
)
what_not_to_do = conf.get(section='derp', key='no', default="jumping")
# "sleep"
until_when = conf.get(section='derp', key='til')
# "brooklyn"
cats = conf.get(section='derp', key='cats')
# "1"
dogs = conf.get(section='derp', key='dogs')
# None
sleep = conf.get(section='herp', key='sleep')
# 1
wait = conf.get(section='herp', key='wait')
# 5.0
timeout = conf.get(section='herp', key='timeout')
# "seventy"
section_exists = conf.has(section='derp')
# True
section_exists = conf.has(section='derp', key='no')
# True
raw_data = conf.raw()
# {
#    'sections': {
#       'herp': {
#          'sleep': 1,
#          'wait': 5.0,
#          'timeout': 'seventy'
#       }
#    },
#    'derp': {
#       'expected': 'the spanish inquisition',
#       'til': 'brooklyn',
#       'cats': '1',
#       'no': 'sleep'
#    }
# }
变更日志
0.1.0 (2018-12-12)
- 特性:添加发布脚本。[Jose Diaz-Gonzalez] 
- 添加对Python 3(至Python 3.7)的支持。[Xavier Hardy] - 添加tox.ini文件,添加.gitignore 
0.0.4 (2013-12-13)
- 将assertDictEquals更改为assertEquals。[Clay Pence] 
- 允许使用自定义配置解析器。[Clay Pence] - 而不是使用ConfigParser.ConfigParser,允许用户传递解析器。 
0.0.3 (2013-05-23)
- 允许从主配置中的条目覆盖confd_path。[Jose Diaz-Gonzalez] 
0.0.2 (2013-04-18)
- 修复主部分始终未创建的问题。[Jose Diaz-Gonzalez] 
0.0.1 (2013-04-14)
- 初始提交。[Jose Diaz-Gonzalez] 
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源分布
         conf_d-0.1.0.tar.gz  (4.6 kB 查看哈希)
      
    构建分发版
        conf_d-0.1.0-py2-none-any.whl (4.5 kB 查看哈希值)
      
    
    
       关闭
    
      
        
    
    
  
conf_d-0.1.0.tar.gz 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | 6230053efae4631350ef7892e6145d7d967bdb7e6e8ca74251a828ecbc5645c6 | |
| MD5 | 53248fda747faf589d6936791988847a | |
| BLAKE2b-256 | 78b8f096e604ae7d2e1116891d83bda96de3f9e68003c5a443216011d8c32038 | 
    
       关闭
    
      
        
    
    
  
conf_d-0.1.0-py2-none-any.whl 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | fe44e8b00b1acca59956949e2fbd83629550e6fbfb55b70106ba07b1451751b7 | |
| MD5 | 8caab3218422c0dfa97f71f39d12d08e | |
| BLAKE2b-256 | 9908bbe0de699a79fb1a10c108556cf9b936cb8673e15949ea6ba6fc45069786 |