What is up with "=="?

Andrew Dalke adalke at mindspring.com
Wed Oct 8 17:54:52 EDT 2003


Quentin Crain:
> 1  Whos __eq__ or __cmp__ is being called: String's or
> Int's?

I suspect the int.  Does it make a difference?

> 2  Why IS comparison supported across types?

Historical implementation reasons.  There used to be no way for
a comparison to raise an exception.  That's changed, but old code
which depended on this hasn't.

> 3  The exception + gives makes it sound like there is
> a built-in function + that does not like taking an
> 'int' and a 'string'. Read this way, the built-in ==
> does accept 'int' and 'string'.

That's an implementation issue I don't know enough about.
Ie, it may be implemented as that even if the implementation
acts identical to one where the tests are done as method of
the type.

                    Andrew
                    dalke at dalkescientific.com






More information about the Python-list mailing list