complex data types?

richard richard at fake.com
Sun Sep 18 10:06:06 EDT 2005


Gustavo Picon <gpicon at aureal.com.pe> wrote in 
news:mailman.550.1127018555.509.python-list at python.org:

> On Sat, 2005-09-17 at 23:34 -0500, Gustavo Picon wrote:
>> 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
>> 
> 
> Actually, forget about that music class, all you need in that example
> is:
> 
> class music:
>     pass

I like that.  I ended up doing:

array = []

title = 't1'
name = 'n1'
songs = ['s1', 's2']
array.append([title,name,songs])
title = 't2'
name = 'n2'
songs = ['s3', 's4']
array.append([title,name,songs])

Thank you and the other posters for the help.

Must learn not to think in c/c++. Python is much easier - no malloc's 
and pointers to fuss with :-)



More information about the Python-list mailing list