Created
January 11, 2016 16:44
-
-
Save jpkotta/c1df14ce4def4a0fe57c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def make_constants(mapping): | |
"""Create a namedtuple of constants | |
These are a poor man's enum. | |
Example: | |
c = make_constants({"ONE":1, "TWO":2, "THREE":3}) | |
c.ONE == 1 | |
:param mapping: A mapping with names as keys and values as values. | |
The names must be valid python identifier strings. | |
:returns: A namedtuple with the values given in mapping | |
:rtype: namedtuple | |
""" | |
nt = namedtuple("_Constants", mapping.viewkeys()) | |
return nt(**mapping) | |
STATUS = make_constants( | |
OrderedDict([ | |
("idle", 0), | |
("start", 1), | |
("success", 2), | |
("fail", 3), | |
("continuous", 4), | |
("stop", 5), | |
])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment