__getitem__ and arguments
Bengt Richter
bokr at oz.net
Sat Jul 19 12:58:57 EDT 2003
On 20 Jul 2003 04:00:05 +0950, Ben Finney <bignose-hates-spam at and-zip-does-too.com.au> wrote:
[...]
>
>> For __getitem__() the arguments become a tuple.
>
>Yes, because you've specified a key, which by definition is a single
>argument.
>
But note that it can be more than a simple tuple (or less, if it's an int):
>>> class X(object):
... def __getitem__(self, i): print i
...
>>> x=X()
>>> x[1]
1
>>> x[1:]
slice(1, None, None)
>>> x[:1]
slice(None, 1, None)
>>> x[:]
slice(None, None, None)
>>> x[1, :, 1:, :1, 1:2, 1:2:3, (4,5), 6]
(1, slice(None, None, None), slice(1, None, None), slice(None, 1, None), slice(1, 2, None),
slice(1, 2, 3), (4, 5), 6)
Notice that (4,5) in there also as one of the indices.
Regards,
Bengt Richter
More information about the Python-list
mailing list