Skip to main content

Robust enumerated type support in Python

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

This package provides a module for robust enumerations in Python.

An enumeration object is created with a sequence of string arguments to the Enum() constructor:

>>> from enum import Enum
>>> Colours = Enum('red', 'blue', 'green')
>>> Weekdays = Enum('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun')

The return value is an immutable sequence object with a value for each of the string arguments. Each value is also available as an attribute named from the corresponding string argument:

>>> pizza_night = Weekdays[4]
>>> shirt_colour = Colours.green

The values are constants that can be compared only with values from the same enumeration; comparison with other values will invoke Python’s fallback comparisons.

>>> pizza_night == Weekdays.fri
True
>>> shirt_colour > Colours.red
True
>>> shirt_colour == "green"
False

Each value from an enumeration exports its sequence index as an integer, and can be coerced to a simple string matching the original arguments used to create the enumeration:

>>> str(pizza_night)
'fri'
>>> shirt_colour.index
2

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

enum-0.4.tar.gz (19.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

enum-0.4-py2.4.egg (1.2 kB view details)

Uploaded Egg

enum-0.4-py2.3.egg (1.2 kB view details)

Uploaded Egg

File details

Details for the file enum-0.4.tar.gz.

File metadata

  • Download URL: enum-0.4.tar.gz
  • Upload date:
  • Size: 19.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for enum-0.4.tar.gz
Algorithm Hash digest
SHA256 0c4bff0403b9cd95ec88399e1ef439bc49c123d9650124aaa02e250a9b7d12c4
MD5 9c01cff144e02a88e0944e7e267e48d1
BLAKE2b-256 3a92de9217b21961433d49cce0e2ef076e4ca29636a57313847670cb4a3fb779

See more details on using hashes here.

File details

Details for the file enum-0.4-py2.4.egg.

File metadata

  • Download URL: enum-0.4-py2.4.egg
  • Upload date:
  • Size: 1.2 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for enum-0.4-py2.4.egg
Algorithm Hash digest
SHA256 12fdad8c262181911ffcf73730781dfdc1f36953cb7fb9f9b02143642950da8f
MD5 07a71e079fd796298a1a59df66e12952
BLAKE2b-256 d4309684c8b5022aac9f9297cdf09f60e43e36a546bb7f05ce2a75fd5377825d

See more details on using hashes here.

File details

Details for the file enum-0.4-py2.3.egg.

File metadata

  • Download URL: enum-0.4-py2.3.egg
  • Upload date:
  • Size: 1.2 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for enum-0.4-py2.3.egg
Algorithm Hash digest
SHA256 a886fbf7fd8f70e3ebee58f239c567e9c23fa74188a72600a7f4cb8eee545c25
MD5 4b51ff7df1defa354a3b544a0c5e6bce
BLAKE2b-256 7becc2fa419e16b4b066934715640fbc52072a02f70c27167225d33e18d0b3ae

See more details on using hashes here.

Supported by

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