0
파이썬에서는 특정 데이터를 기반으로 동등성을 유지해야하는 클래스에 대해 평등과 해시를 재정의해야하는 경우가 자주 있습니다. 나는 보통 이것을 이와 같은 수퍼 클래스로 추상화하지만, 파이썬에 이와 비슷한 것이 있는지 궁금해하고 있습니다. 일반적인 작업처럼 보입니다.python valuetype hash mixin
class ValueType(object):
def __init__(self, *args, **kwargs): super(ValueType, self).__init__(*args, **kwargs)
def __eq__(self, other): return self._key() == other._key()
def __ne__(self, other): return self._key() != other._key()
def __hash__(self): return hash(self._key())
정확히 원하는지는 모르지만 [total_ordering] (http://docs.python.org/library/functools)을 살펴볼 가치가 있습니다. .html # functools.total_ordering) –
불행히도, 수업에는 총 주문이 없습니다. – Antimony