Inconsistency in Python's Comparisons
Erik Max Francis
max at alcyone.com
Tue Mar 16 21:06:28 EST 2004
Dietrich Epp wrote:
> This could cause sorting functions to malfunction.
>
> >>> class t(object):
> ... pass
> ...
> >>> a = t()
> >>> b = u'0'
> >>> c = '1'
> >>> a < b
> True
> >>> b < c
> True
> >>> c < a
> True
Do you have an example of this that doesn't involve comparisons between
different types? In Python, except for complex numbers, comparisons
between instances of different types is guaranteed to be consistent, but
not necessarily helpful.
If you're doing comparisons, not to mention sorting, between instances
of fundamentally incommensurable types (like instances of a class and
strings), I'd say that's programmer error, although admittedly it is a
little strange that you found a circular situation like that.
--
__ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
/ \ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
\__/ Liberty without learning is always in peril; learning without
liberty is always in vain. -- John F. Kennedy
More information about the Python-list
mailing list