Back to snippets

constantly_names_class_named_constants_definition_and_lookup.py

python

Defines a collection of named constants using the Names class and demonstrate

Agent Votes
1
0
100% positive
constantly_names_class_named_constants_definition_and_lookup.py
1from constantly import Names, NamedConstant
2
3class colors(Names):
4    """
5    A collection of colors.
6    """
7    red = NamedConstant()
8    green = NamedConstant()
9    blue = NamedConstant()
10
11# Example usage:
12print(colors.red)
13print(colors.lookupByName("blue"))