Last active
April 24, 2024 17:14
-
-
Save CodeByAidan/6edaad976f1ca0eb814dd2306a7bd175 to your computer and use it in GitHub Desktop.
An example using EnumMeta, with EASE!
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
>>> from enum import EnumMeta, Enum | |
>>> Color3 = EnumMeta('Color3', (Enum,), (_ := EnumMeta.__prepare__( | |
... 'Color3', (Enum,),)) and any(map(_.__setitem__, *(zip(*{ | |
... 'RED': 1, | |
... 'GREEN': 2, | |
... 'BLUE': 3, | |
... }.items())))) or _ | |
... ) | |
>>> print(Color3(1)) # or without print(): <Color3.RED: 1> | |
Color3.RED |
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
from enum import EnumMeta, Enum | |
Color3 = EnumMeta('Color3', (Enum,), (_ := EnumMeta.__prepare__( | |
'Color3', (Enum,),)) and any(map(_.__setitem__, *(zip(*{ | |
'RED': 1, | |
'GREEN': 2, | |
'BLUE': 3, | |
}.items())))) or _ | |
) | |
print(repr(Color3(1))) # <Color3.RED: 1> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment