How to determine what called __cmp__ method?
David Ascher
DavidA at ActiveState.com
Sat Oct 21 00:55:25 EDT 2000
On Fri, 20 Oct 2000, Pearu Peterson wrote:
>
> I have the following situation:
>
> >>> foo(1) < foo(2)
>
> where
>
> class foo:
> def __init__(self,i):
> self.i = i
> def __cmp__(self,obj):
> # who called me???
> return self.i<obj.i or -(self.i>obj.i) or 0
>
> The question is how to determine inside __cmp__ method where it was
> called? That is I want to know was it called for evaluating
> either inequality '<', or '>', or '<=', or ...?
I don't think there's a way. The logic is hidden in the C layer, and you
don't get to see it.
Now, with rich comparisons.. =) (If anyone is interested in taking on the
work of creating the rich comparisons patches, pushing the PEP through,
etc., get in touch with me).
--david ascher
More information about the Python-list
mailing list