[Tutor] Basics of Classes

Harm_Kirchhoff at mail.digital.co.jp Harm_Kirchhoff at mail.digital.co.jp
Sun Oct 26 19:46:27 EST 2003


First of all, thanks for the feedback on my last question, the responses 
helped me to make good progress in understanding python.

Over the weekend I read through Mark Lutz & David Asher's Learning Python 
and started fumbling with classes. (I come from M/MUMPS which is an old 
language and does not know the concept of OOP or classes.)

I copied their example o p. 166 and ... got an error:

>>> class harm:
        def __getitem__(self, index):
                return index ** 2

 
>>> a3=harm
>>> print a3 [2]
Traceback (most recent call last):
  File "<pyshell#41>", line 1, in ?
    print a3 [2]
TypeError: unsubscriptable object
>>> 

I would like to write a class, that handles the in/output to my ZODB (I am 
not that far yet, but its the goal).
Ideally I would like to have an instance to which I can assign data as if 
it were a multidimensional db:

Sales [2003] ['Jan'] ['Cape Verde'] = (Quantity, Turnover)

All the rest (input validation, storage, ...) should be handled by the 
instance.

Any idea why my instance is 'unsubscriptable' ?



More information about the Tutor mailing list