要跨模块使用的全局configparser对象
klang-globconf的Python项目详细描述
全局配置
创建全局configparser对象,而不考虑需要它的项目和模块
开始
在项目中:
from globconf import config
# config will attempt to read local config.ini file if present - otherwise:
if 'important section' not in config.sections():
config.read_string("""
[important section]
host = critical-system.com
user = REST_USER
pwd = REST_PASSWORD
verify_ssl = false
""")
# or config.read('some_other_config.ini')
# load class using globconf.config
在模块中:
from globconf import config, verify_required_options
class module(object):
def __init__(self):
sec = 'service now'
self.cfg = verify_required_options(sec, ['host', 'user', 'pwd'])
if not self.cfg.getboolean('verify_ssl', fallback=True):
import urllib3
urllib3.disable_warnings(InsecureRequestWarning)
只要有人在全局配置中初始化了所需的部分,您的模块就会很高兴。
先决条件
配置分析器
安装
一个循序渐进的示例系列,告诉您如何使开发环境运行
Give the example
然后重复
until finished
以从系统中获取一些数据或将其用于小演示为例结束
套餐
python setup.py sdist
测试
pytest
或
pyton -m unittest
作者
- steffen schumacher-初始工作-steffenschumacher
许可证
这个项目是在麻省理工学院的许可下授权的-详细信息请参见LICENSE.md文件
致谢
- 向任何使用过代码的人提供帽子小费
- 灵感
- 等