I would like to create a new class that acts as a special type of container for objects, and can be accessed using square brackets.
For example, suppose I have a class called ListWrapper. Suppose obj is a ListWrapper. When I say obj[0], I expect the method obj.access() to be called with 0 as an argument. Then, I can return whatever I want. Is this possible?
You want to define the special
__getitem__[docs] method.Result: