On Dec 9, 2007 3:21 PM, hashcollision <<a href="mailto:hashcollision@gmail.com">hashcollision@gmail.com</a>> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>From <a href="http://ivory.idyll.org/blog/dec-07/conversions.html" target="_blank">http://ivory.idyll.org/blog/dec-07/conversions.html</a>:</div>
<div><pre>class X:
internal = [5,6,7,8]
def __getitem__(self, i):
return self.internal[i]
x = X()
l = [1,2,3]
print l + x
</pre>
<p>fails with</p><pre>TypeError: can only concatenate list (not "instance") to list</pre></div></blockquote><div>If you want class X to understand "+" via duck-typing, overload __add__ and __radd__.<br>
</div></div><br>-- <br>Daniel Stutzbach, Ph.D. President, Stutzbach Enterprises LLC