一个python模块,用于以关键字样式json格式管理配置文件。
kwconfig的Python项目详细描述
用法
importkwconfig# Specify a file path for creating kwconfig objectconfig=kwconfig.manage('config.json',defaults={'key0':'value0'})# Update the config file with a key and value dictconfig.update({'key1':'value1','key2':'value2'})# Add a keyword dict to existing config file# If a key exists, it will be updated# If a key does not exist, it will be addedother_config={'key3':'value3'}other_config=config.add(other_config)# Write new values using keyword dictconfig.overwrite({'new_key1':'new_value1','new_key2':'new_value2'})# Obtain a dict of the config file contentskw=config.read()# Remove the key named "key1"config.remove('key1')# Reset to defaultsconfig.reset()# Parsing a keyword list into dict ----# Create a sample list of keyword argumentsargv=['--key1=value1','--key2=value2']# Parse into a keyword dictkwdict=kwconfig.parse(argv)# View the values of key1 and key2print('key1: '+kwdict['key1'])print('key2: '+kwdict['key2'])
有关更多用法详细信息,请参见Documentation。
开发人员注释
开发者安装
使用来自github的pip安装最新的开发人员版本:
pip install git+https://github.com/rrwen/kwconfig
从git克隆源安装:
- 确保git已安装
- 克隆到当前路径
- 通过pip 安装
git clone https://github.com/rrwen/kwconfig cd kwconfig pip install . -I
测试
- 克隆到当前路径git clone https://github.com/rrwen/kwconfig
- 进入文件夹cd kwconfig
- 确保unittest可用
- 运行测试
pip install . -I python -m unittest
文档维护
- 确保sphinx已安装pip install -U sphinx
- 更新docs/ 中的文档
pip install . -I sphinx-build -b html docs/source docs