Module csw.EnumUtil
Classes
class UpperCaseEnum (*args, **kwds)
-
Expand source code
class UpperCaseEnum(Enum): @classmethod def fromString(cls, s: str): match s: case "Container": u = s case _: u = s.upper() if u in cls._member_names_: return cls[u] raise KeyError(f"{u} is not a member of Enum ({', '.join(cls._member_names_)})") @classmethod def list(cls): return list(map(lambda c: c.value, cls))
Create a collection of name/value pairs.
Example enumeration:
>>> class Color(Enum): ... RED = 1 ... BLUE = 2 ... GREEN = 3
Access them by:
- attribute access:
Color.RED
- value lookup:
Color(1)
- name lookup:
Color['RED']
Enumerations can be iterated over, and know how many members they have:
>>> len(Color) 3
>>> list(Color) [<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]
Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.
Ancestors
- enum.Enum
Subclasses
Static methods
def fromString(s: str)
def list()