Class-override of a sort-key method?
Hi all - it would seem that these days, all the cool kids use the sort function's 'key' kwarg in order to sort a list of custom objects quickly. Unfortunately, as opposed to using 'cmp', where you can implent __cmp__ to get 'automatic sorting' in a similar fashion, there doesn't seem to be a direct analogue for a class-overridable method for providing a sort key. (ie, something like '__sortkey__' or '__key__'). Is there one, and I'm just missing it? If not, are there any plans to add one? (I did a quick search of the PEP list, and the only hits for 'sort' I saw had to do with sorting dictionaries by value). - Paul -- http://mail.python.org/mailman/listinfo/python-list
A 'foolproof' way to query inheritance tree? numbers.Real in 2.6)
Generally, if I want to know the inheritance tree of a class, I either use inspect.getmro or __bases__ However, after reading about the new numbers module / class tower in Python 2.6/3.0, I realized that both of these will fail to show that the 'float' type actually inherits from numbers.Real: >>> import inspect, numbers >>> issubclass(float, numbers.Real) True >>> inspect.getmro(float) (, ) >>> float.__bases__ (,) Is there a more foolproof way to query this information? Or is this simply some sort of bug with the new implementation of numbers in python 2.6? - Paul -- http://mail.python.org/mailman/listinfo/python-list
