0

So i got a hardcoded class in my python project for enum use/purposes like this:

class Actions(Enum):
    go_to = 1
    open = 2
    close = 3
    ...

The class will not have any further functionality.

But I would like it to be more dynamic like the user to be able to define actions in a json file and then create the aforementioned Actions class from the json file (or any other file type).

Is this possible in python?

Thanks!

Stelix
  • 9
  • 2
  • If you want it to be dynamic use a dictionary. – Klaus D. Oct 19 '21 at 10:21
  • does it answer your question: https://stackoverflow.com/questions/33690064/dynamically-create-an-enum-with-custom-values-in-python ? Or this: https://stackoverflow.com/questions/28126314/adding-members-to-python-enums/35899963 ? – Grysik Oct 19 '21 at 10:36
  • @Grysik ha! I think this first post results in what i need. Though, I understand that this way, resonably enough, sicnce I create the enum on runtime it can not be interpreted by intelisense! The project compliles and seems to produces the expected results however! – Stelix Oct 19 '21 at 11:51
  • Yeah, dynamic creation and intelisense is rather bad idea ;) . However intelisense should work with it correctly during debugging. – Grysik Oct 19 '21 at 12:58

0 Answers0