defining __getitem__
Nathan Froyd
froydnj at rose-hulman.edu
Wed Apr 26 23:02:15 EDT 2000
In article <WiMN4.1$7C.101 at news.hananet.net>, Gang Seong Lee wrote:
>I'd like to have a method __getitem__ in a class which acts like other
>sequence type.
>For example,
>------------------------
>class data:
> def __init__(self, n):
> self.maxsize = n
>
> def __getitem__(self, k):
> if k >= self.maxsize:
> # I want to stop here
> # ????
raise IndexError
I believe...
--
</nathan> froydnj at rose-hulman.edu | http://www.rose-hulman.edu/~froydnj/
More information about the Python-list
mailing list