Control of flow

Campbell cb921 at voice.co.za
Tue Jul 31 08:33:23 EDT 2001


Hi,

I use python to write telephony apps, and I find that a 'goto' is often
a nice tool (stop going 'aargh', its properly "useful" sometimes =).

Here is a little snippet that gets a month/day from a caller.  If the
day entered is not in the range of days valid for the month entered, we
repeat from the top.  Does anyone have a few minutes to waste helping
me??  How better can I code things that look like this:

>>> snip <<<
while 1:
    cont = 1         ## ugh!
    month = getdtmf("enter2digs.vox", 2)
    if month < 1 or month > 12:
        play("invalidmonth.vox")
        continue
    while 1:
        day = getdtmf("enterday", 2)
        if day < 1 or day > Month[month]:
            play("invalidday.vox")
            cont = 1
        cont = 0
    if cont == 1:
        continue
    break
>>> snip <<<

It gets worse quite easily.  And because there's a person on the other
end of the phone hearing the files and entering keypad digits, I must
dumb down the program to their level, sometimes ending up with a huge
string of while 1:'s and half-job loop control variables like cont.

Thank you,
  Thank you,
   Campbell.
    The world is our spoon
     tick, tock.






More information about the Python-list mailing list