parameters process
Project description
Parameters is design for large program with massive parameters. It supports integer, float, bool, string and enumerate(enum) types. Array is supported for bool, integer and float. For enum type, customized value can be set as well. Data type is protected. And load/dump of parameters/config is available.
Get instance
You can get an emptry instance, or load from dict/filename/filehandler
params = paraparser.Parameters()
params = paraparser.Parameters(paramters_dict)
params = paraparser.Parameters(parameter_json)
Load config/parameters
After the parameter instance is generated, you can load from a dict/file as well.
params.LOAD_CONFIG(config_file)
params.LOAD_PARAMETERS(parameters_file)
You can check parameters.json.sample & config.json.sample for details of parameters/config.
update/remove key
Key can be updated/removed, val can be set/reset
>>> params.UPDATE_KEY('test_key', 'int', default=0)
>>> params
{"test_key": 0}
>>> params.test_key = 1
>>> params
{"test_key": 1}
>>> params.test_key
1
>>> params.REMOVE_KEY('test_key')
>>> params.RESET_KEY('test_key')
>>> params
{"test_key": 0}
Special Types
Array
An integer/float/bool array could be initiate with
>>> params.UPDATE_KEY('test_key', 'int', isArray=True, length=10, default=0)
>>> params
{"test_key": "[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"}
>>> params.UPDATE_KEY('test_key', 'float', isArray=True, length=6, default=0)
>>> params
{"test_key": "[0.0, 0.0, 0.0, 0.0, 0.0, 0.0]"}
Enumerate
We highly improved enum type
>>> params.UPDATE_KEY('test_key', 'enum', enumItems=['x1', 'x2', 'x3'], default='x1')
>>> params
{
"test_key": "x1"
}
>>> params.test_key
key test_key: x1
enums: ['x1', 'x2', 'x3']
You can customize enuemrate enumerate values with enumVals, which is really useful when cooperating with old programs.
>>> params.UPDATE_KEY('test_key', 'enum', enumItems=['x1', 'x2', 'x3'], enumVals=['-1', '2', '5'], default='x1')
>>> params
{
"test_key": "x1"
}
>>> print(params.DUMP_OUTPUT())
test_key = -1
Type Protection
Type is protected within paraparser, e.g.
>>> params.UPDATE_KEY('test_key', 'enum', enumItems=['x1', 'x2', 'x3'], enumVals=['-1', '2', '5'], default='x1')
>>> params
{
"test_key": "x1"
}
>>> params.test_key = 'x22'
AssertionError: Parameters Errror: key "test_key" is a enum, items: ['x1', 'x2', 'x3']
And the same for other types.
Output
A beautiful output is available with the instance or use the print function
>>> print(params)
{
"string": "STRINGSING",
"int": 1,
"float": 1.1,
"enum": "1",
"floatArray": [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ],
"runType": "geometry_converge",
"ialgo": "method1"
}
You could also dump the config with DUMP_CONFIG(), or dump the parameters with DUMP_PARAMETERS() to standard output or to a file/handler
>>> params.DUMP_CONFIG()
{'test_key': {'key': 'test_key', 'type': 'float', 'enumItems': None, 'enumVals': None, 'isArray': True, 'length': 6, 'default': 0.0, 'comments': '', 'reference': ''}}
>>> params.DUMP_PARAMETERS()
{'__keys_config': {'test_key': {'key': 'test_key', 'type': 'float', 'enumItems': None, 'enumVals': None, 'isArray': True, 'length': 6, 'default': 0.0, 'comments': '', 'reference': ''}}, '__keys_values': {'test_key': [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]}}
>>> params.DUMP_CONFIG('config.json')
>>> params.DUMP_PARAMETERS('parameters.json')
Have Fun!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file paraparser-1.0.0.tar.gz
.
File metadata
- Download URL: paraparser-1.0.0.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.9.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 312150a84c0b84fdfe1e6e549c43ac08b1bf6154e70b038db1891289997175a1 |
|
MD5 | a1eb8e7a8a1f888c831a372ff548509f |
|
BLAKE2b-256 | c05fac1af25214d18100380e9df48c95596180bece36ee6c70dc6b4074f715de |
File details
Details for the file paraparser-1.0.0-py2.py3-none-any.whl
.
File metadata
- Download URL: paraparser-1.0.0-py2.py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.9.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26ba71fba85819b4b64eb9aeb4b3c6277e1ab04d7eba7e51691fd80ed5574f33 |
|
MD5 | 0bea6e47570f3f38b250fc29ca824175 |
|
BLAKE2b-256 | e7639c9b86a482c5637aecbb46c46ce093a1e226b1f96246446bd6e4e90bb61b |