Python 3.0 - is this true?
duncan-news at grisby.org
Tue Nov 11 11:15:09 CET 2008
In article <mailman.3754.1226330191.3487.python-list at python.org>,
Terry Reedy <tjreedy at udel.edu> wrote:
>> I have an object database written in Python. It, like Python, is
>> dynamically typed. It heavily relies on being able to sort lists where
>> some of the members are None. To some extent, it also sorts lists of
>> other mixed types. It will be very hard to migrate this aspect of it
>> to Python 3.
>Very Hard? Several key functions have been suggested on this thread.
>Given that 2.x only sorts most but not all types and that the sort is
>only guaranteed to be consistent within a session, as I remember, I
>suspect you can choose or write something at least as good for your
Yes, very hard. There are only ever simple types in the lists --
strings, integers, Nones, very occasionally floats, and lists of those
things. The sort is always predictable with those types. Just because
you can contrive situations to demonstrate unpredictable sorts doesn't
mean that all sorts with mixed types are unpredictable.
The sorting is in a performance-critical part of the system, so the
overhead of evaluating a key function is not insignificant. A key
function that returns objects that contrive to emulate the
functionality of a comparison function is definitely not appropriate.
That area of the system already builds the lists using C++ for speed,
so if we ever migrate to Python 3 it will probably be easier to do the
whole thing in C++ rather than jump through hoops to make the Python
sort work efficiently enough.
-- Duncan Grisby --
-- duncan at grisby.org --
-- http://www.grisby.org --
More information about the Python-list