__getitem__ and arguments

KanZen kanzen at mail.com
Sat Jul 19 05:10:25 EDT 2003


I'm trying to understand the difference between __setitem__ and an
ordinary method. For example:

>>> class A(object):
      def __getitem__(self, *args):
        print len(args)
      def normalMethod(self, *args):
        print len(args)

>>> a=A()
>>> a.normalMethod(1, 2, 3)
3
>>> a[1, 2, 3]
1

For __getitem__() the arguments become a tuple. I can't seem to find
this in the language spec. Can anybody explain this to me?

Thanks,
KanZen.




More information about the Python-list mailing list