---------- Forwarded message ---------- From: Guilherme Polo <[EMAIL PROTECTED]> Date: 09/12/2007 19:45 Subject: Re: [Python-3000] Possible Duck Typing Problem in Python 2.5? To: hashcollision <[EMAIL PROTECTED]>, [EMAIL PROTECTED]
2007/12/9, hashcollision <[EMAIL PROTECTED]>: > From http://ivory.idyll.org/blog/dec-07/conversions.html: > class X: > internal = [5,6,7,8] > def __getitem__(self, i): > return self.internal[i] > > x = X() > > l = [1,2,3] > print l + x > > > > fails withTypeError: can only concatenate list (not "instance") to list > I tried: > class X(list): > internal = [5, 6, 7, 8] > > def __getitem__(self, i): > return self.internal[i] > def __len__(self): > return internal > def __iter__(self): > return internal.__iter__() > but this fails also. Try this: class X(list): internal = [5, 6, 7, 8] def __init__(self): list.__init__(self, self.internal) x = X() l = [1,2,3] print l + x > IMHO, this is a problem. Is it? If so, I suggest that it be fixed in python > 3000. > > _______________________________________________ > Python-3000 mailing list > Python-3000@python.org > http://mail.python.org/mailman/listinfo/python-3000 > Unsubscribe: > http://mail.python.org/mailman/options/python-3000/ggpolo%40gmail.com > > -- -- Guilherme H. Polo Goncalves _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com