例子中__cmp__()方法为什么不直接return cmp(self.name, s.name)
class Student(object):
def __init__(self, name, score):
self.name = name
self.score = score
def __str__(self):
return '(%s: %s)' % (self.name, self.score)
__repr__ = __str__
def __cmp__(self, s):
return cmp(self.name, s.name) #这样不是更简洁
L = [Student('Tim', 99), Student('Bob', 88), Student('Alice', 77)]
print sorted(L)