I not only want to compare class *instances* but also the classes
themselves. Something like:

class T(object):
    @classmethod
    def __cmp__(cls, other):
        return cmp(cls.__name__, other.__name__)
    @instancemethod
    def __cmp__(self, other):
        return cmp(self.x, other.x)

class B(T): pass
class A(T): pass

sorted([B, A]) => [A, B]

My motivation for doing so is simply to sort classes based on their
names and not (as it seems is the default behaviour) on the order in
which they were created.

I guess I could always just do something like sorted(classes,
key=lambda cls: cls.__name__)...but where's the fun in that? :-)

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to