Misunderstanding classes (newbie)

Jerry 2jerry at writeme.com
Wed Feb 23 00:07:41 CET 2000


This is just a list of class elements ? no ?
class lm:
   def __init__(self, last=None,first=None,age=0):
       self.lastname=last
       self.firstname=first
       self.age=age

then ..
list_lm=[]
a=lm('jerome','VACHER',29)
list_lm.append(a)
list_lm.append(lm('paul','DUBOIS',45))
a[0].lastname='jerome'

Is that you want ?

Best Regard, Jerry the foolish dracomorpheus, - france -


sorry at spam.invalid a écrit dans le message ...
>Hi,
>
>I'm a Python newbie (and an OOP newbie) trying to
>construct a class that:
>
>  (a) behaves like a list but has a FORTRAN-like variable
>      starting index,
>  (b) has per-index attributes.
>
>i.e. Each element of the list has two (or more) attributes,
>     and, by default, the first element is at x[1].
>
>e.g. x[1].lastname, x[1].firstname, x[1].age
>     x[2].lastname, x[2].firstname, x[2].age
>
>I seem to be able to get each part of the solution
>independently (the first part by using UserList and
>__getitem__), but when I attempt to combine them, I
>clearly don't understand what I'm doing.
>
>Suggestions?
>
>Thanx.
>
>P.S. Please respond to the list.





More information about the Python-list mailing list