I really don't get where the error is in this little piece of code:
class Personne:
def __init__(self, nom, prenom):
print("Appel de la méthode __init__")
self.nom = nom
self.prenom = prenom
def __new__(cls, nom, prenom):
print("Appel de la méthode __new__ de la classe {}".format(cls))
return object.__new__(cls, nom, prenom)
personne = Personne("Doe", "John")
It is giving me the error:
Traceback (most recent call last):
File "/home/bilal/Lien vers python/21_meta_classes/1_instanciation.py", line 21, in <module>
personne = Personne("Doe", "John")
File "/home/bilal/Lien vers python/21_meta_classes/1_instanciation.py", line 14, in __new__
return object.__new__(cls, nom, prenom)
TypeError: object() takes no parameters
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…