Hi, I need to configure a script with a command line switch and/or environment variable (-> string) to a list of enums. I found the following to work:
from enum import Enum class Provider(Enum): NONE = 0, '' Amazon = 40, 'Amazon' Netflix = 42, 'Netflix' SkyTicket = 104, 'Sky Ticket' AmazonChannels = 140, 'Amazon Channels' Disney = 176, 'Disney+' def __new__(cls, value, name): member = object.__new__(cls) member._value_ = value member.fullname = name return member def __int__(self): return self.value def __str__(self): return self.fullname providers = [] test = "Amazon, AmazonChannels, Netflix, Disney, SkyTicket" for t in test.split(','): providers.append(Provider[t.strip()]) print(providers) I would prefer a more direct input string like "Provider.Amazon, Provider.Netfilx" Any idea? Or even a better way from cli option to enum list? Josef -- https://mail.python.org/mailman/listinfo/python-list