Comparison of different types does not throw exception

Philipp Weinfurter philipprw at gmx.at
Fri Jul 13 14:42:44 CEST 2001


On Fri, 13 Jul 2001, Nils O. Selåsdal <noselasd at frisurf.no> wrote:
> "Gordon Williams" <g_will at cyberus.ca> wrote in message
>> I would like to know why python does not produce an exception when a
>> comparison of objects of different types is made.  For example:
>>
>> >>> 1 < "aaa"
>> 1
[...]
> In any OO language its desired to take advantage og polymorphisme,
> and let comparison between diffrent objects be allowed.The programmer
> is responsible,
> for providing comparison functions.
> I wanna know if my User also equals my SecureUser....

hmm, i'm still new to python, so please correct me if i'm wrong here.
but since you can not subclass `integer' and `string' (and override the 
comparison operators for those types), there is not much polymorphism here.
and as the language reference states:
"Otherwise, objects of different types always compare unequal, and are
ordered consistently but arbitrarily."
i, too, think that this doesn't make much sense.

philipp



More information about the Python-list mailing list