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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file constancy-0.2.0.tar.gz.

File metadata

  • Download URL: constancy-0.2.0.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for constancy-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ed3cdc91876b863d26558425df883e76701c77f2cb5a25a8916abae1013c0004
MD5 eddae265b4e28472896a9daaa5cc45c2
BLAKE2b-256 d37eeba61a30b4d61c7779120de59a454f94c8eec19dcf33c913eebf88df4043

See more details on using hashes here.

File details

Details for the file constancy-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: constancy-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for constancy-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ea28b9cea2d2e39f3a7793e097d6f30134df719dd42b2e6a5e78b4d777ed66b4
MD5 7354e7f1df22686218c75eddef942631
BLAKE2b-256 64bac3f0d2c4a37e8517e0025dde75498de8df9ffe7b94a0e2c43251afa6fb12

See more details on using hashes here.

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