__getitem__ AttributeError
Jeroen Valcke
jeroen at valcke.com
Wed Nov 1 13:49:53 EST 2000
Alex Martelli wrote:
<snip>
> and class Slidelist does not define a __getitem__ method,
> so its instances cannot be indexed with [] nor iterated on
> with for.
>
> If I understand your intentions correctly, the __getitem__
> method you may need in the Slidelist class may be one that
> just delegates to the self.slidelist attribute of the
> instance (you _are_ naming *quite a few* disparate things
> "slidelist", here, aren't you...?), i.e.:
>
> class Slidelist:
> def __init__(self):
> self.slidelist = []
> def __getitem__(self, index):
> return self.slidelist[index]
> # etc, rest of class snipped
>
> Alex
Yep, this seems to resolve the problem. Thanks
I'm a bit clueless though, how can I know when to define this class? Is
this overloading?
--
Jeroen Valcke jeroen at valcke.com
ICQ# 30116911 Home: http://www.valcke.com/jeroen/
Phone +32(0)56 32 91 37 Mobile +32(0)486 88 21 26
The road of excess leads to the palace of wisdom (W. Blake)
More information about the Python-list
mailing list