finding the right data structure...?
Robert Brewer
fumanchu at amor.org
Thu Jun 10 19:02:21 EDT 2004
David Hoare wrote:
> I have an application in VB that I was using as a sample to
> 're-create'
> it using python. It involved storing information about sound
> and light
> cues (this was for a lighting / sound theater controller).
>
> The data was stored like this:
> - a custom 'type' called lightCue which looked like this:
> > Type lightCue
> > Name As String 'optional short name
> > Description As String 'optional longer description
> > CueLine As String 'optional line in script where cue occurs
> > upTime As Single 'time for lights fading UP
> > downTime As Single 'time for lights fading down
> > chanLevel(0 To maxChan) As Single 'stored intensity
> level (0 to 100) for each channel on the lighting console
> > End Type
>
> I then created an array...
> dim lq(1 to 200) as lightCue
> ...allowing me to iterate through the list of cues for any
> information I
> needed
>
> I am struggling to come up with a similar (in function) way
> to do this
> in Python. Any ideas? I think I understand about classes, but then I
> need to 'name' each instance of that class when they are
> created, don't I?
No, you don't need to name each instance. Start with a simple class like
this:
class LightCue(object):
def __init__(self, name='', description=''):
self.name = name
self.description = description
self.cueLine = ''
self.upTime = 0.0
self.downTime = 0.0
self.chanLevel = [0.0] * maxChan
...then create a Python list of them instead of a VB array...possibly:
cues = []
for name in names:
newCue = LightCue(name)
cues.append(newCue)
...in which case, "cues[44]" will return the appropriate LightCue.
Embellish as necessary.
Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org
More information about the Python-list
mailing list