请问为什么是这样的报错?怎样嵌入函数实现需求?
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__ @classmethod def _cmp_name(se,s): if se.name>s.name: return 1 elif se.name<s.name: return -1 else: 0 def __cmp__(self, s): if self.score>s.score: return 1 elif self.score<s.score: return -1 else: Student._cmp_name(self,s) L = [Student('Tim', 99), Student('Bob', 88), Student('Alice', 99)] print sorted(L)
Traceback (most recent call last):
File "./6251/1paK/index.py", line 29, in
print sorted(L)
File "./6251/1paK/index.py", line 26, in __cmp__
Student._cmp_name(self,s)
TypeError: _cmp_name() takes exactly 2 arguments (3 given)