Skip to content

Instantly share code, notes, and snippets.

@CodeByAidan
Last active April 24, 2024 17:14
Show Gist options
  • Save CodeByAidan/6edaad976f1ca0eb814dd2306a7bd175 to your computer and use it in GitHub Desktop.
Save CodeByAidan/6edaad976f1ca0eb814dd2306a7bd175 to your computer and use it in GitHub Desktop.
An example using EnumMeta, with EASE!
>>> 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
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