Skip to main content

Container for constants.

Project description

python-constancy

Container for constants.

test PyPI version license: MIT code style: black

Installing

pip install constancy

Example:

from constancy import Constants

Create container for constants

>>> DAYS = Constants(
...     MON=0,
...     TUE=1,
...     WED=2,
...     THU=3,
...     FRI=4,
...     SAT=5,
...     SUN=6
... )

Get value from container

>>> DAYS.MON
0
>>> DAYS['MON']
0

Represent with pure python data structures

>>> list(DAYS)
['MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN']
>>> dict(DAYS)
{'WED': 2, 'SUN': 6, 'FRI': 4, 'THU': 3, 'MON': 0, 'TUE': 1, 'SAT': 5}

All constants are immutable

>>> DAYS.MON = 7
...
AttributeError: Immutable attribute

>>> del DAYS.MON
...
AttributeError: Immutable attribute

Autocomplete only for constants

>>> dir(DAYS)
['FRI', 'MON', 'SAT', 'SUN', 'THU', 'TUE', 'WED']

Sorting like list.sort

>>> DAYS.sort(key=lambda k, v: v, reverse=True)
>>> list(DAYS)
['SUN', 'SAT', 'FRI', 'THU', 'WED', 'TUE', 'MON']

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

constancy-0.2.0.tar.gz (3.2 kB view hashes)

Uploaded Source

Built Distribution

constancy-0.2.0-py3-none-any.whl (3.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page