Comparison of different types does not throw exception

Gordon Williams g_will at cyberus.ca
Thu Jul 12 11:54:18 EDT 2001


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

I cant see why anyone would like to have comparisons of different types as
it has no meaning.  It is a programming error and an exception should be
produced.

This one tripped me up in an assert statement for a couple of hours.  The
assert statement was returning true when it should have been false to give
me a warning that there was a problem.  It was something like:

lengthA= 3
lengthB= "2"

assert lengthA <= lengthB

and was returning true


It would have been *much* more helpful if it told be that I was comparing
objects of different types.

Regards,

Gordon Williams





More information about the Python-list mailing list