I asked a question along these lines a few posts back, but I am
finding it difficult and possibly impossible to imitate one of the
features I found in this c++ class. So say I have a class:

class foo():

        def __init__(self, data):
                self.data = data

        def __getitem__(self, index):
                return self.data[index]

        def __setitem__(self, key, item):
                self.data[key] = item

This allows me to do this:

obj = foo( [1, 2, 3, 4, 5, 6] )
print obj[1]

Now what I want to do, at least what this C++ program is doing is
this:

print obj[1][1]

Is there a way to overload the [ ] operators twice in a row like that?
Or do I have no choice but to create an array in an array if I want to
mimic the C++ program. I guess I could just use __call__ to return the
index needed to retrieve the correct index from the matrix and write
something like this:

print obj[obj(1,1)]

But that doesnt look as clear as [1][1] and I just want to know if its
possible.

RyanT
Technical Artist
Naughty Dog Inc.
www.rtrowbridge.com/blog


--~--~---------~--~----~------------~-------~--~----~
Yours,
Maya-Python Club Team.
-~----------~----~----~----~------~----~------~--~---

Reply via email to