Annoying behaviour of the != operator

Jordan Rastrick jrastrick at
Wed Jun 8 23:09:33 CEST 2005

I'm a Maths and Philosophy undergraduate first and foremost, with
Computer Science as a tacked on third; I've studied a fair bit of logic
both informally and formally, and am familiar with things such as the
non-nessecity of the law of the excluded middle in an arbitrary
propositional calculus farmework.

I can now also see the usefulness of overriding != and == to do things
other than simple equality comparison. Kay Schueler's Expr class seems
like a particularily elegant and beautful example! (and seems to me a
much better justification for rich comparisons than the rather mundane
typying-reduction case of Numeric arrays)

So I'm not arguing Python should demand != and not(a == b) return the
same thing all the time (although I did question this in my original
post). My argument is simply one of pragmatism - cases where this is
not the case are the highly unusual ones, and so they should be the
ones forced to write seperate __eq__ and __ne__ methods, In *every*
example that's been rased so far - Floats, Numeric.array, Expr,
(hypothetically) some unusual Symbolic Logic program without the law of
excluded middle - these methods are both by nessecity independently
defined, and my suggestion would not change the status quo at all.

Mahesh raised the argument some posts back that Python should not 'just
guess' what you want. But the problem is, it *already does* - it
guesses you want object identity comparison if you haven't written
__ne__. But if __ne__ is not provided, than the negation of


is *surely* a better guess for a != b than the negation of

a is b

As always, explicit is better than implicit. But if we're going to be
implicit, lets be implicit in the way that makes the most sense. I
can't stand Perl's autoconversion from strings to integers. But how
much worse would it be if strings were auto-converted to, for example,
the sum of the ordinal value of their ascii characters?

OK, thats about as compelling as I can make the argument. If Perl
bashing won't sway Python fans over, I don't know what will :)

P.S. Excuse the excessive presence typos throughout all my posts, its
been a long night.

More information about the Python-list mailing list