__cmp__ between dissimilar objects

insyte at gmail.com insyte at gmail.com
Tue Nov 14 11:39:13 EST 2006


> why not just inherit from datetime instead?

I'll probably do that in the next iteration.

> or read footnote 4 under "supported operations" on this page for info on how to
> implement mixed-type comparisions:
>
>     http://docs.python.org/lib/datetime-datetime.html

OK.  I added a 'timetuple' attribute to my class.  Now comparisons seem
to "just work".  This has made it even more obvious to me that I don't
understand how comparisons function:

If the GeneralizedTime instance is on the LHS of the comparison and the
datetime instance on the RHS, why would datetime's __cmp__ method be
called?  I assume its being called since GeneralizedTime sure doesn't
care whether or not it has a timetuple attribute...

I've read through the "Basic customization" section of the language
reference, which doesn't seem to describe a scenario where the __cmp__
method on the RHS is called.

Thanks...

-Ben




More information about the Python-list mailing list