Python 3.0 - is this true?

Peter Otten __peter__ at web.de
Sat Nov 8 19:42:01 CET 2008


walterbyrd wrote:

> I have read that in Python 3.0, the following will raise an exception:
> 
>>>> [2, 1, 'A'].sort()
> 
> Will that raise an exception? 

Yes.

>>> [2, 1, "a"].sort()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unorderable types: str() < int()

> And, if so, why are they doing this? How 
> is this helpful? Is this new "enhancement" Pythonic?

Is 1 > "A"? Is ord("B") > "A", "11" > 10? 
What happens for sorted([datetime.time(), "now"])? 

As the Zen puts it:

"In the face of ambiguity, refuse the temptation to guess."

So yes, I think this is an enhancement, and a pythonic one.

Peter



More information about the Python-list mailing list