I have a loop that process each item in a sequence and after each item some updating is done to some variables. However i don't what these variable updated if we are processing the last item in the list. i could put in a conditional and test if the list is now empty after popping items from the list... but testing for an empty list and the bookkeeping of maintaining the popped list seems horribly inefficient and this is for a real time multimedia playback type situation so learning a more efficient idiom for this seems worth while:
You won't have all the dependancies... including the player (STEREO) and some tables of durations.. but you get the gist: def playall(startime, amp, wet_percent, rest_percent, duty_factor, smpl_lst): ''' a play-loop that plays all samples in a directory, just once with some temporal padding and also returns the end of the last duration so that the begining of the next section can be determined''' event = 1; inskip = 0; inchan = 0; incr = 0 for sample in smpl_lst: splt = os.path.split(sample) rtinput(sample) loc = random.random() dur = DUR() STEREO(startime, inskip, dur, amp, loc) print "event no. %d @ %.2f (dur: %.2f, end: %.2f) --> sf: %s : [flag: %.2f]" % (event, startime, dur, startime+dur, splt[1], dry) incr = (dur * duty_factor) + kptools.windex(kptools.durations) startime = startime + incr restflag = random.random() if (restflag < rest_percent): rest = kptools.windex(kptools.rest) print "\n", "<>-" * 8, "[ rest : ", rest, "]", "-<>" * 8, "\n" startime = startime + rest event = event + 1 print '\n', 'Next start = ', startime, '\n\n' so what i am trying to do its skip that if (restflag < rest_percent): biz on the last item if we are on our last sequence item. The rests (which are random) is for padding between events and since we have just played our last event, we don't want any extra padding so that our next call of the loop starts at the proper time (just at the last event of this loop is over). The loop function will calculate the next start time, and return it so that we can use it as the start time argument for our next call of the loop. so if i want to play 7 items i might get something like: loop_call_01: item_1 item_2 rest item_3 rest item_4 item_5 item_6 rest item_7 (but we don't want any rest here ever! cause we might want our next loop to start w/o any pause) gosh.. i hope this is clear.... anyway that's my query .. hehe ... cheers, kevin _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor