Effective constant management tools
Project description
Const-Utils
const-utils
is a small-yet-effective library that offers some
tools for working with Python constants. Its main feature is
the Constant Class, which includes utilities for accessing
constants, stored within a container class.
Defining constant classes is available by using ConstClassMeta
(as a metaclass), or the standard BaseConstClass
(by inheritance).
Examples
Creating a constant class
class CountryConsts(BaseConstClass):
US = 'United States of America'
UK = 'United Kingdom'
Access options
Access from the class itself
>>> CountryConsts.as_dict() # {'US': 'United States of America', 'UK': 'United Kingdom'}
>>> CountryConsts['US'] # 'United States of America
>>> Country.const_names # ['US, 'UK']
>>> Country.const_values # ['United States of America', 'United Kingdom']
Access global/local constants
>>> # Access current global/local constants (depends on kwarg `local`)
>>> # as a dictionary of names to values
>>> access_namespace_consts(local=False)
Storing class constants to a namespace
>>> # Store constants in a module
>>> CountryConsts.apply_to_module('some_module_name', override=True)
>>> # Store constants as globals
>>> CountryConsts.apply()
>>> # Store constants as locals
>>> CountryConsts.apply(local=True)
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
const_utils-0.0.1.tar.gz
(6.2 kB
view hashes)
Built Distribution
Close
Hashes for const_utils-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f5f87a9068b60486eba9e44182d7f5165f655c15e743e514704cd5c4483e499 |
|
MD5 | 1e7ac6a621c75e37dac07d1eec239b7f |
|
BLAKE2b-256 | fe83d7baa046bab289d0e4e0f35b46d6d489bee970e128115949ec596720d666 |