On Fri, Sep 14, 2012 at 8:16 AM, Albert-Jan Roskam <fo...@yahoo.com> wrote: > > Am I abusing the __getitem__ method, or is this just a creative way of using > it?
No, you're using it the normal way. The item to get can be an index, a key, or even a slice. http://docs.python.org/reference/datamodel.html#object.__getitem__ > if not isinstance(key, (int, float)): > raise TypeError Instead you could raise a TypeError if "not hasattr(key, '__int__')" since later you call int(key). > if abs(key) > self.nCases: > raise IndexError You might also want to support slicing. Here's an example: http://stackoverflow.com/a/2936876/205580 _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor