class C:
def __init__(self,n,x):
self.n = n
self.x = x
a = C('a',1)
b = C('b',2)
c = C('c',3)
classList = [b,a,c]
for q in classList: print q.n,
classList.sort(lambda a,b: long(a.x - b.x))
for q in classList: print q.n,
运行上面的代码会得到错误TypeError: comparison function must return int, not long
。是否有另一种干净的方法可以按某些类变量对类对象进行排序?