How does compare work?

Helmut Jarausch jarausch at skynet.be
Mon Jan 26 22:28:31 CET 2004


Hi,

what does Python do if two objects aren't comparable (to my opinion)
If I've understood "Python in a Nutschell" correctly it should raise an
exception but it doesn't do for me.

Here are two examples

if 2 > '1' : print "greater"
else       : print "less_or_equal"

   prints  less_or_equal

and

class C:
     def __init__(self): pass

X=C()
if 2 > X : print "greater"

   prints  greater

In both cases I don't get an exception.
But I'd like to since these lead to hard-to-find bugs.

Thanks for shedding some light on this.

P.S. This is Python 2.4 (CVS)

-- 
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany



More information about the Python-list mailing list