def __cmp(self, op, other):
if not isinstance(other, str):
return NotImplemented
# Do case-insensitive comparison?
# Make copies to avoid infinite recursion.
o = str(other)
if o == o.lower():
s = str(self.lower())
else:
s = str(self)
if op in (operator.__eq__, operator.__ne__, operator.__contains__):
return op(s, o)
elif self.isdigit():
return op(int(s), len(o))
elif other.isdigit():
return op(len(s), int(o))
else:
return op(s, o)
评论列表
文章目录