iter jitters
Diez B. Roggisch
deetsNOSPAM at web.de
Tue May 4 18:19:23 EDT 2004
Steven Brent wrote:
> Btw, I just realized that a custom __getitem__ method I defined earlier
> in the module(and unhelpfully didnt post), handles the iteration in 2
> lines!
>
> def __getitem__(self, index):
> return self.data[index]
>
> This is the kind of thing I was after, because I didn't want any
> iteration going on in the __iter__ definition itself. Trying to reinvent
> the wheel for exercise.
Interesting. Just played around with my example and found that in case of
absence of an __iter__-method the for - in generates keys from 0 to - well,
I guess something like max_int, but I won't wait so long... - and then
tries __getitem__ with that key.
--
Regards,
Diez B. Roggisch
More information about the Python-list
mailing list