'elixir like atoms in python?

I am building a project in python that requires the use of a small state machine. I could of course just make a bunch of states like

__StateOne__ = 0
__StateTwo__ = 1
__StateThree__ = 2
# etc

and then just keep track with something like state = _StateOne_, but I was hoping to be able to do something like elixir style atoms. Would this be possible with some import or third party library?



Solution 1:[1]

Use enums:

from enum import Enum

states = Enum('<a descriptive name>', 'one two three four')

states.one, states.two, states.three... are now sorta like atoms, for your purposes.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 knrz