我尝试实施__concat__
,但没有成功
>>> class lHolder():
... def __init__(self,l):
... self.l=l
... def __concat__(self, l2):
... return self.l+l2
... def __iter__(self):
... return self.l.__iter__()
...
>>> lHolder([1])+[2]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'lHolder' and 'list'
我怎样才能解决这个问题?
__concat__
不是一个特殊的方法(http://docs.python.org/glossary.html#term-special-method http://docs.python.org/glossary.html#term-special-method)。它是操作员模块的一部分。
您将需要实施__add__
得到你想要的行为。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)