Separating __cmp__ from < and > ?

Huaiyu Zhu hzhu at localhost.localdomain
Mon Aug 14 20:35:49 EDT 2000


In many situations it is conceptually possible to have a!=b without either
a<b or a>b.  Mathematically, this is the case for objects that live in a
partially ordered space.

For example, I want all the following to be false (not really on lists but
on user defined classes of similar nature)

[1,2] == [2,1]
[1,2] < [2,1]
[1,2] > [2,1]

Is it possible to simulate this in Python?  The __cmp__ function seems to be
defined with a well-ordering in mind, as it's not allowed to return None in
addition to positive, negative and zero.  There is neither separate __lt__
and __gt__ that could divorce < and > from == and !=.

Any ideas for getting around this limitation?

Huaiyu



More information about the Python-list mailing list