J'ai une classe Point
avec x
y y
attributs. J'aimerais obtenir False
la comparaison d'un Point
avec n'importe quel autre type d'objet. Par exemple, Point(0, 1) == None
ne fonctionne pas :
AttributeError: 'NoneType' object has no attribute 'x'
La classe :
class Point():
def __init__(self, x, y):
self.x = x
self.y = y
def __eq__(self, other):
return self.x == other.x and self.y == other.y
def __ne__(self, other):
return not self.__eq__(other)
Comment configurer __eq__
pour obtenir False
par rapport à tout autre type d'objet ?