This question was marked as duplicate of another question. I am not asking how to create enumerations, I'm asking how to create constants, and that is the difference between the questions.
This question was marked as duplicate of yet another question. While the answers do explain how to create constants in python
they don't explain how to create them in Enum
like style, which is what my question is asking for.
I need to create constants in my python
code. I don't want the user to be able to modify them. I found this, but it is not exactly what I need. I need to be be able to use them just like enums, without creating and instance.
For example:
class MyConstClass(object):
Const0 = 0
Const1 = 1
Const2 = 2
myfunc(MyConstClass.Const0)
MyConstClass.Const1 = 20 # Raise an exception
I also don't want to create a module, just like it is done here
Is there a way to do it?