Elixir, like atoms in python?

I am creating a python project that requires the use of a small state machine. I could of course do a bunch of states like

__StateOne__ = 0
__StateTwo__ = 1
__StateThree__ = 2
# etc

      

and then just keep track of something like state = __StateOne__, but I was hoping I could do something like elixir style atomistics . Is this possible with any import or third party library?

+3


source to share


1 answer


Use enums:

from enum import Enum

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

      



states.one

, states.two

, states.three

... are now sorted as atoms for your purposes.

+3


source







All Articles