First code:
class myClass(object): def __cmp__(self, other): return cmp(type(self), type(other)) or cmp(self.__something, other.__something)
Does this mean the same order as for other types in python? Is there a proper idiom for this?
Related Question:
Looking back a bit on google, I found some relevant information in python docs . Citation:
Implementation Note:. Objects of various types, with the exception of numbers, are ordered by their type names; objects of the same types that do not support the correct comparison are ordered by their address.
This suggests that if I want to follow this behavior, I should use
class myClass(object): def __cmp__(self, other): return (cmp(self.__class__.__name__, other.__class__.__name) or cmp(self.__something, other.__something))
It is especially sad that I can have an extremely difficult time preserving transitivity with dict s, which is a special case that I was hoping to implement.
Do I need to check the types of my arguments? Does python even let me see this?
source share