complex data types?

rixil at hotmail.com rixil at hotmail.com
Sun Sep 18 00:22:37 EDT 2005


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.

If you show us where array[0] and array[1] are being initialized, it
would be easier to diagnose the problem.

At the same time, if array[0].songs equals array[1] songs, you are
probably initializing both array[0] and array[1] with the same object.
Since array[0] and array[1] both refer to the same object, a change to
one will be reflected in the other.

I hope this is what you're looking for.

Michael Loritsch




More information about the Python-list mailing list