Question about isinstance()
reply.in.the.newsgroup at my.address.is.invalid
Fri Jan 27 10:55:24 CET 2006
>>> def __eq__(self, other):
>>> return self.an_attribute == other.an_attribute
>>> except AttributeError:
>>> return False
>> This may give unexpected results when you compare a foo with an instance
>> of a completely different type that happens to have an attribute called
>That's a trade-off, isn't it?
>On the one hand, you risk false negatives, by refusing to compare against
>things you didn't think of.
Well no, when comparing against things you didn't think of the __eq__
shouldn't return a false False, it should return NotImplemented. After
all, the things you didn't think of are not (yet) implemented.
"A rich comparison method may return NotImplemented if it does not
implement the operation for a given pair of arguments."
Wat wil jij worden? http://www.carrieretijger.nl
More information about the Python-list