"pconst" library provide you const-like function on Python.
Project description
# pconst
"pconst" library provide you const-like function on Python.
# Install
Currently preparing to install via pip.
# How to use
You can set constants to const module's attribute.
```py
from pconst import const
const.APPLE_PRICE = 100
const.APPLE_NAME = 'apple'
print(const.APPLE_PRICE)
```
```
100
```
If try to update constant value, ConstantError will be raised.
```py
const.APPLE_PRICE = 200
```
```
Constant value of "APPLE_PRICE" is not editable.
```
del operator is also disallowed.
```py
del const.APPLE_NAME
```
```
ConstantError: Constant values are not deletable.
```
You can also set dict and list value to const module, and they will be not editable (if dict or list values contains dict or list, then will be applied recursively.).
```py
const.APPLE_DATA = {
'prince': 100,
'name': 'apple',
'sales_list': [12300, 25000, 8200]}
print('price:', const.APPLE_DATA['price'])
print('name:', const.APPLE_DATA['name'])
print('sales_list:', const.APPLE_DATA['sales_list'])
```
```
price: 100
name: apple
sales_list: [12300, 25000, 8200]
```
```py
const.APPLE_DATA['price'] = 200
```
```
ConstantError: Update dict value is not allowed.
```
```py
const.APPLE_DATA['sales_list'][1] = 9800
```
```
ConstantError: Constant list value is not allowed.
```
The dict or list class method that will not change the values is be able to access (e.g., len(), keys()).
```py
print(len(const.APPLE_DATA['sales_list']))
```
```
3
```
```py
print(const.APPLE_DATA.keys())
```
```
dict_keys(['price', 'name', 'sales_list'])
```
Conversely, if the method that will change the dict or list values, it will raise error.
```py
const.APPLE_DATA.update({'season': 'winter'})
```
```
ConstantError: To update dict values is not allowed.
```
# For test
Test will be run by nose library (https://nose.readthedocs.io/en/latest/).
```
# pip install nose
```
Probably this pip command requires "Run as Administrator".
Then move to pconst directory, and run following command:
```
$ nosetests -s
```
"pconst" library provide you const-like function on Python.
# Install
Currently preparing to install via pip.
# How to use
You can set constants to const module's attribute.
```py
from pconst import const
const.APPLE_PRICE = 100
const.APPLE_NAME = 'apple'
print(const.APPLE_PRICE)
```
```
100
```
If try to update constant value, ConstantError will be raised.
```py
const.APPLE_PRICE = 200
```
```
Constant value of "APPLE_PRICE" is not editable.
```
del operator is also disallowed.
```py
del const.APPLE_NAME
```
```
ConstantError: Constant values are not deletable.
```
You can also set dict and list value to const module, and they will be not editable (if dict or list values contains dict or list, then will be applied recursively.).
```py
const.APPLE_DATA = {
'prince': 100,
'name': 'apple',
'sales_list': [12300, 25000, 8200]}
print('price:', const.APPLE_DATA['price'])
print('name:', const.APPLE_DATA['name'])
print('sales_list:', const.APPLE_DATA['sales_list'])
```
```
price: 100
name: apple
sales_list: [12300, 25000, 8200]
```
```py
const.APPLE_DATA['price'] = 200
```
```
ConstantError: Update dict value is not allowed.
```
```py
const.APPLE_DATA['sales_list'][1] = 9800
```
```
ConstantError: Constant list value is not allowed.
```
The dict or list class method that will not change the values is be able to access (e.g., len(), keys()).
```py
print(len(const.APPLE_DATA['sales_list']))
```
```
3
```
```py
print(const.APPLE_DATA.keys())
```
```
dict_keys(['price', 'name', 'sales_list'])
```
Conversely, if the method that will change the dict or list values, it will raise error.
```py
const.APPLE_DATA.update({'season': 'winter'})
```
```
ConstantError: To update dict values is not allowed.
```
# For test
Test will be run by nose library (https://nose.readthedocs.io/en/latest/).
```
# pip install nose
```
Probably this pip command requires "Run as Administrator".
Then move to pconst directory, and run following command:
```
$ nosetests -s
```
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pconst-1.0.0.tar.gz
(5.0 kB
view details)
Built Distribution
File details
Details for the file pconst-1.0.0.tar.gz
.
File metadata
- Download URL: pconst-1.0.0.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce73a39bb6400d803c4e3a65be77b7af20745f39144b4306de7617e20bed9b23 |
|
MD5 | 04c3867e868cdba0f07a7d0852fa6278 |
|
BLAKE2b-256 | 0dafb9fdf45f5bb699b854aa72dc53f6891c578f1196b195656a154208a3054e |
File details
Details for the file pconst-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: pconst-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 225965c897ab809adf133d775bfdf00d07cc41130d223cfacaf148ad03bc7db4 |
|
MD5 | e2e1cb2d91a8d9f059f3102fc479ade2 |
|
BLAKE2b-256 | 8cecd53e01e0661591280bd85c8f384e0761efaffae3eccf6e13ee97908acc37 |