On Sat, 2005-09-17 at 20:49 -0500, richard wrote: > I'd like to have an array in which the elements are various data types. > How do I do this in Python? > > For example: > > array[0].artist = 'genesis' > array[0].album = 'foxtrot' > array[0].songs = ['watcher', 'time table', 'friday'] > array[1].artist = 'beatles' > array[1].album = 'abbey road' > array[1].songs = ['come', 'something', 'maxwell'] > > Everything I try generates errors or results in array[0].songs equaling > array[1].songs. I feel I'm missing something obvious.
Maybe something like this? class music(object): def __init__(self): self.lst = {} def __setattr__(self, name, value): self.__dict__[name] = value array = [] array.append(music()) array.append(music()) # begin quoting your code array[0].artist = 'genesis' array[0].album = 'foxtrot' array[0].songs = ['watcher', 'time table', 'friday'] array[1].artist = 'beatles' array[1].album = 'abbey road' array[1].songs = ['come', 'something', 'maxwell'] # end quoting your code print array[0].artist print array[1].artist print array[0].songs print array[1].songs -- Gustavo Picon (http://tabo.aurealsys.com/) Aureal Systems S.A.C. (http://www.aureal.com.pe/) [EMAIL PROTECTED] Tlf: (511) 243-0131 Nextel: 9824*4625
signature.asc
Description: This is a digitally signed message part
-- http://mail.python.org/mailman/listinfo/python-list