Enum module supporting sequence, bitmask, and string enumerations
Yet Another Enumerator is an enum module that supports three different types of enumerations:
- sequence enums (0, 1, 2, 3, etc.)
- base 2 bitmask enums (0, 1, 2, 4, 8, etc.)
- string enums (‘top’,’bottom’,’left’,’right’, etc.)
Each Enumeration is its own class, with instances of that class being singletons. Besides being a value, enum instances can also have their own behavior (use case, anyone?).
Creating an enum is as simple as:
from yaenum import Enum, BitMaskEnum, UniqueEnum, enum Enum.create('Color', 'red green blue', export=globals())
class Color(BitMaskEnum): # python 3+ only black red green blue
and if that’s too magical for you:
class Color(BitMaskEnum): black = enum() # python 2: enum(value=0) etc. red = enum() green = enum() blue = enum()
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.