I'm trying to understand the difference between __setitem__ and an
ordinary method. For example:
[color=blue][color=green][color=darkred]
>>> class A(object):[/color][/color][/color]
def __getitem__(sel f, *args):
print len(args)
def normalMethod(se lf, *args):
print len(args)
[color=blue][color=green][color=darkred]
>>> a=A()
>>> a.normalMethod( 1, 2, 3)[/color][/color][/color]
3[color=blue][color=green][color=darkred]
>>> a[1, 2, 3][/color][/color][/color]
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.
ordinary method. For example:
[color=blue][color=green][color=darkred]
>>> class A(object):[/color][/color][/color]
def __getitem__(sel f, *args):
print len(args)
def normalMethod(se lf, *args):
print len(args)
[color=blue][color=green][color=darkred]
>>> a=A()
>>> a.normalMethod( 1, 2, 3)[/color][/color][/color]
3[color=blue][color=green][color=darkred]
>>> a[1, 2, 3][/color][/color][/color]
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.
Comment