Python enum: 'TypeError: Error when calling the metaclass bases: module.__init__() takes at most 2 arguments (3 given)' beheben
English
Deutsch
Problem:
Sie möchten in Python eine class von enum wie folgt ableiten:
broken_enum_example.py
import enum
class MyEnum(enum):
X = 1
Y = 2classaber beim Ausführen sehen Sie eine Fehlermeldung wie diese:
enum_traceback.txt
Traceback (most recent call last):
File "test.py", line 3, in <module>
class MyEnum(enum):
TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given)Lösung
Sie versuchen nicht, von der Enum-Klasse (mit großem E!) zu erben, sondern vom enum-Modul!
Dies ist die korrekte Syntax:
fixed_enum_example.py
from enum import Enum
class MyEnum(Enum):
X = 1
Y = 2Check out similar posts by category:
Python
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow