As @MichaelHoff noted , Enum behavior is to treat names with the same values ββas aliases 1 .
You can get around this using the Advanced Enum 2 library:
from aenum import Enum, NoAlias class Token(Enum): _settings_ = NoAlias facebook = { 'access_period': 0, 'plan_name': '', } instagram = { 'access_period': 0, 'plan_name': '', } twitter = { 'access_period': 0, 'plan_name': '', } if __name__ == "__main__": print list(Token)
Exit now:
[ <Token.twitter: {'plan_name': '', 'access_period': 0}>, <Token.facebook: {'plan_name': '', 'access_period': 0}>, <Token.instagram: {'plan_name': '', 'access_period': 0}>, ]
To reinforce what Michael said: Enum members must be constant - you should not use inconsistent values ββunless you really know what you are doing.
Best example of using NoAlias :
class CardNumber(Enum): _order_ = 'EIGHT NINE TEN JACK QUEEN KING ACE'
1 See this answer for standard use of Enum .
2 Disclosure: I am the author of Python stdlib Enum , enum34 backport , and the Advanced Enumeration ( aenum ) library.
source share