My question:
It seems that __getattr__
is not called for indexing operations, ie I can\'t use __getattr__
on a class
Python bypasses __getattr__
, __getattribute__
, and the instance dict when looking up "special" methods for implementing language mechanics. (For the most part, special methods are ones with two underscores on each side of the name.) If you were expecting i[0]
to invoke i.__getitem__(0)
, which would in turn invoke i.__getattr__('__getitem__')(0)
, that's why that didn't happen.