用于项目配置管理的小工具
p-config的Python项目详细描述
Python的简单项目配置。在
您可以使用它从环境或本地文件读取配置。在
安装
$: pip install p_config
利用
假设有一些配置文件。在
^{pr2}$# filename: override.ymlserver:port:443hostname:localhostbackends:-127.0.0.1:80
您可以通过这种方式读取配置
$:envSERVER.PORT=8080ipythonPython3.6.9(default,Nov72019,10:44:02)Type'copyright','credits'or'license'formoreinformationIPython7.13.0--AnenhancedInteractivePython.Type'?'forhelp.\ In[1]:fromp_configimportConfigIn[2]:config=Config('default.yml')In[3]:config['SERVER.PORT']Out[3]:80In[4]:config['SERVER.HOSTNAME']Out[4]:'localhost'In[5]:config.load('override.yml')# update configuration via local fileIn[6]:config['SERVER.PORT']Out[6]:443In[7]:config['SERVER.BACKENDS']Out[7]:['127.0.0.1:8080']In[8]:config.load_env()# update configuration via environIn[9]:config['SERVER.PORT']Out[9]:'8080'In[10]:config.get('SERVER.PORT')Out[10]:'8080'In[11]:config.get('NONE_EXIST')Out[11]:None
- 项目
标签: