python中如何更好的地重写__eq__,python重写__eq__,魔法方法class my


魔法方法

class myclass:     def __eq__(self, other):

他重写了所有的==,操作.
而我想要的效果是,仅当与同类比较时候采用这个__eq__
请问如何优雅地实现

#目前的做法,但不优雅 def __eq__(self, other):        if type(other)==type(self):            return self.value==other.value        else:            super(SBTNode, self).__eq__(other)

不知道更简洁的

编橙之家文章,

评论关闭