# 请您Star Please Star
如果你觉得此工具不错,请轻轻点击此页面右上角**Star**按钮增加项目曝光度,谢谢!
If you think this tool is good, please gently click the **Star** button in the upper right corner at this page to increase the project exposure, thank you!
# 中文文档
[点此查看中文文档](https://github.com/NaiboWang/CommandlineConfig/blob/master/Readme_CN.md)
# Easy-to-use Commandline Configuration Tool
A library for users to write (experiment in research) configurations in Python Dict or JSON format, read and write parameter value via `dot .` in code, while can read parameters from the command line to modify values.
标签 Labels: Python, Command Line, commandline, config, configuration, parameters, 命令行,配置,传参,参数值修改。
Github URL: <https://github.com/NaiboWang/CommandlineConfig>
## New Features
### v2.2.*
* Support infinite level nesting of parameters in dictionary
* Automatic version checking
* Support parameter value constrained to specified value (enumeration)
* Support for tuple type
* Support reading configuration from local JSON file
* Support for setting parameter help and printing parameter descriptions via command line `-h`
* Documentation updates, provide simple example
## Simple Example
```python
# Install via pip
pip install commandline_config
# import package
from commandline_config import Config
# Define configuration dictionary
config = {
"index":1,
"lr": 0.1,
"dbinfo":{
"username": "NUS"
}
}
# Generate configuration class based on configuration dict
c = Config(config)
# Print the configuration of the parameters
print(c)
# Read and write parameters directly via dot . and support multiple layers.
c.index = 2
c.dbinfo.username = "ZJU"
print(c.index, c.dbinfo.username, c["lr"])
# On the command line, modify the parameter values with --
python example.py --index 3 --dbinfo.username XDU
# Get the parameter descriptions via the help method in the code, or on the command line via -h or -help (customization required, see detailed documentation below for details)
c.help()
python example.py -h
```
## Catalogue
- [请您Star Please Star](#请您star-please-star)
- [中文文档](#中文文档)
- [Easy-to-use Commandline Configuration Tool](#easy-to-use-commandline-configuration-tool)
- [New Features](#new-features)
- [v2.2.*](#v22)
- [Simple Example](#simple-example)
- [Catalogue](#catalogue)
- [Usage](#usage)
- [Please submit issue](#please-submit-issue)
- [Installation](#installation)
- [Configuration Way](#configuration-way)
- [Configuration parameters read and write method](#configuration-parameters-read-and-write-method)
- [Write method](#write-method)
- [Reading method](#reading-method)
- [Pass configuration to functions](#pass-configuration-to-functions)
- [Copy configuration](#copy-configuration)
- [Store configuration parameters to local file or database](#store-configuration-parameters-to-local-file-or-database)
- [Advanced options](#advanced-options)
- [Restrict parameter input values to fixed enum types](#restrict-parameter-input-values-to-fixed-enum-types)
- [Print parameter help descriptions](#print-parameter-help-descriptions)
- [Set parameter descriptions](#set-parameter-descriptions)
- [Print parameter help](#print-parameter-help)
- [Things need attention](#things-need-attention)
- [Conflict with Argparse](#conflict-with-argparse)
- [Input value forced conversion](#input-value-forced-conversion)
- [The list parameter needs to be assigned with a backslash before the string element quotes when passing by commandline](#the-list-parameter-needs-to-be-assigned-with-a-backslash-before-the-string-element-quotes-when-passing-by-commandline)
- [Quotes are required for command-line assignment of tuple parameters, and string elements must be preceded by a backslash](#quotes-are-required-for-command-line-assignment-of-tuple-parameters-and-string-elements-must-be-preceded-by-a-backslash)
- [Parameter naming convention](#parameter-naming-convention)
- [Unlimited layer of nested objects](#unlimited-layer-of-nested-objects)
- [Parameter integrity check, all parameters to be modified must be predefined](#parameter-integrity-check-all-parameters-to-be-modified-must-be-predefined)
- [Special configurations in zsh environment](#special-configurations-in-zsh-environment)
- [Full conversion example](#full-conversion-example)
- [Example Running Script](#example-running-script)
- [Shattered thoughts](#shattered-thoughts)
- [TODO](#todo)
## Usage
### Please submit issue
If you encounter any problems during using with this tool, please raise an issue in the github page of this project, I will solve the bugs and problems encountered at the first time.
**Meanwhile, welcome to submit issues to propose what functions you want to add to this tool and I will implement them when possible.**
### Installation
There are two ways to install this library:
* 1. Install via pip:
```shell
pip install commandline_config
```
If already installed, you can upgrade it by the following command:
```shell
pip install commandline_config --upgrade
```
* 2. Import the commandline_config.py file directly from the `/commandline_config` folder of the github project into your own project directory, you need to install the dependency package `prettytable`:
```shell
pip install prettytable
```
Or install via `requirements.txt`:
```shell
pip install -r requirements.txt
```
### Configuration Way
* 0. Import library:
```python
from commandline_config import Config
```
* 1. Set the parameter name and initial value in JSON/Python Dict format, and add the parameter description by `#` comment. Currently supports nesting a dict inside another dict, and **can nest unlimited layers**.
```python
preset_config = {
"index": 1, # Index of party
"dataset": "mnist",
'lr': 0.01, # learning rate
'normalization': True,
"pair": (1,2),
"multi_information": [1, 0.5, 'test', "TEST"], # list
"dbinfo": {
"username": "NUS",
"password": 123456,
"retry_interval_time": 5.5,
"save_password": False,
"pair": ("test",3),
"multi":{
"test":0.01,
},
"certificate_info": ["1", 2, [3.5]],
}
}
```
That is, the initial configuration of the program is generated. Each key defined in `preset_config` dict is the parameter name and each value is the initial value of the parameter, and at the same time, the initial value type of the parameter is automatically detected according to the type of the set value.
The above configuration contains seven parameters: `index, dataset, batch, normalization, pair, multi_information and dbinfo`, where the type of the parameter **index** is automatically detected as **int**, the default value is **1** and the description is "Index of party".
Similarly, The type and default value of the second to fifth parameter are string: `"mnist"; float:0.01; bool:True; tuple:(1,2); list:[1,0.5,'test', "TEST"]`.
The seventh parameter is a nested dictionary of type dict, which also contains 7 parameters, with the same type and default values as the first 7 parameters, and will not be repeated here.
* 2. Create a configuration class object by passing `preset_config` dict to `Config` in any function you want.
```python
if __name__ == '__main__':
config = Config(preset_config)
# Or give the configuration a name:
config_with_name = Config(preset_config, name="Federated Learning Experiments")
# Or you can store the preset_config in local file configuration.json and pass the filename to the Config class.
config_fr
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
简洁命令行配置工具 一个供用户以Python Dict或JSON格式编写(科研中实验)配置的库,在代码中用点.读写属性,同时可以从命令行中读取参数配置并修改参数值。 支持字典内参数无限层级嵌套 自动版本检查 支持参数值限定为指定值(枚举) 支持元组类型tuple 支持从本地JSON文件中读取配置 可设置参数帮助,并通过命令行-h打印参数说明 文档更新提供简单示例 安装: pip install commandline_config 使用方式与注意事项见README.md文档
资源推荐
资源详情
资源评论
收起资源包目录
commandline-config-master.zip (10个子文件)
commandline-config-master
new_version.cmd 119B
setup.py 1KB
LICENSE 1KB
Readme_CN.md 32KB
example.py 4KB
requirements.txt 18B
commandline_config
__init__.py 39B
commandline_config.py 14KB
.gitignore 79B
Readme.md 35KB
共 10 条
- 1
资源评论
十小大
- 粉丝: 9168
- 资源: 2553
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功