PDA

View Full Version : audio object string


Jerry
03-13-2008, 10:01 AM
The following script contains a function which attempts to play
an audio file which is passed as
an argument. Before calling the function I want to construct the
name of the audio object by concatenating character strings, but
it doesn't work. Can you tell me the correct way to do this?


from viz import *

go()

sound1 = add('boing!.wav')

def playit(snd):
snd.play()

num = 1
s = 'sound'+str(num)

playit(s)

farshizzo
03-13-2008, 11:06 AM
Are you trying to look up a Python object by its name? The following will look up the name in the current global variable scope and play the sound if it exists:def playit(snd):
soundObject = globals().get(snd,None)
if soundObject is not None:
soundObject.play()