Attack a sacred Python Cow
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Sat Jul 26 03:58:39 EDT 2008
Matthew Fitzgibbons a écrit :
(snip)
> As for !=, it seems like there is a technical reason for the behavior.
> Remember, there is no default __ne__ method, so the behavior you want
> would have to live in the interpreter. If __ne__ isn't defined, it would
> have to try to call __eq__ and negate the result. Is there any other
> lookup that is treated this way?
There are quite a few cases in Python where there are both a specific
magic method *and* a default behaviour based on another magic method if
the specific one is not implemented. Just out of my mind:
* __contains__ and __getitem__
* __iter__ and __getitem__
* __nonzero__ and __len__
Not to mention the fact that lookup rules even check the existence of
special methods on class attributes (remember the descriptor protocol ?)...
More information about the Python-list
mailing list