I'd like to generate some types at runtime from a config file. For simplity, let's assume I already have the data loaded as a python dictionary:
color_values = dict(RED = 1, YELLOW = 2, GREEN = 3) How can I transform this into the type (using enum)
class Color(enum.Enum): RED = 1 YELLOW = 2 GREEN = 3 The following doesn't work
def make_enum(name, values): return type(name, (enum.Enum,), values) >>> Color = make_enum('Color', color_values) AttributeError: 'dict' object has no attribute '_member_names'
enum.Enum, which would just tell me to use it. Of course, you're right that it shows the example I needed there.