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 > [EMAIL PROTECTED] > http://mail.python.org/mailman/listinfo/python-3000 > Unsubscribe: > http://mail.python.org/mailman/options/python-3000/ggpolo%40gmail.com > > -- -- Guilherme H. Polo Goncalves -- http://mail.python.org/mailman/listinfo/python-list