Why doesn't this work?
[color=blue][color=green][color=darkred]
>>> def foo(lst):[/color][/color][/color]
.... class baz(object):
.... def __getitem__(cls , idx): return cls.lst[idx]
.... __getitem__=cla ssmethod(__geti tem__)
.... baz.lst = lst
.... return baz
....[color=blue][color=green][color=darkred]
>>> f = foo([1,2,3])
>>> f[0][/color][/color][/color]
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: unsubscriptable object[color=blue][color=green][color=darkred]
>>> f.__getitem__(0 )[/color][/color][/color]
1[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]
I thought x[y] and x.__getitem__(y ) were supposed to always be
synonymous.
Thanks,
rg
Comment