我有一节课看起来是这样的:
class Foo(object):
def __init__(self, a, b, c=None):
self.a = a
self.b = b
self.c = c # c is presumed to be a list
def __eq__(self, other):
return self.a == other.a and self.b == other.b
但是,在本例中,“c”可能是一个foo列表,其中“c”包含foo列表,例如:
[Foo(1,2), Foo(3,4,[Foo(5,6)])]
在给定列表结构/对象结构的情况下,处理这种类型的对象比较的好方法是什么?我假设仅仅做self.c == other.c
是不够的。你知道吗
修复
__eq__
方法Foo中
n
属性的通用解决方案:相关问题 更多 >
编程相关推荐