The Industry choice

Nick Coghlan ncoghlan at iinet.net.au
Sun Jan 2 00:56:15 EST 2005


Paul Rubin wrote:
> I don't see that big a problem.  The current Python sorting routine
> operates on instances of class "object" and calls the __cmp__ method
> to do comparisons.  Every class of sortable objects either defines a
> __cmp__ method or inherits one from some superclass, and sort calls
> those methods.  Static type declarations would not require writing any
> additional sorting routines.

Python's list.sort doesn't check the *type* of the arguments at all. It only 
looks for the relevant comparison methods (__cmp__ or __lt__, as I recall).

Sure, classes written in *Python* will ultimately inherit from either object or 
types.ClassType, but extension classes need not do any such thing.

Yet list.sort works with them all, anyway.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at email.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.skystorm.net



More information about the Python-list mailing list