In the Absence of a GoTo Statement: Newbie needs menu-launcher to choose amongst sub-programs

Ron Stephens rdsteph at earthlink.net
Fri Apr 13 16:26:38 EDT 2001


Wow. Thanks. That sure does it. Now, when the function is executed in this
example, where does control in the program return to immediately after the
function finishes executing? Doe sit retrun to  the beginning of hte while
loop? I guess so, in which case this elegantly re-asks the user the questioons
in case the user wants to re-run a differeetn program...Thanks!

Paul Prescod wrote:

> Ron Stephens wrote:
> >
> >...
> >
> > So, now  I consider procedural menu program using raw_input. Still, how
> > do I go to the appropriate sub-program when the user chooses one? With
> > goto's this would be trivial. Now, I consider a nested set of "if "
> > statements that determines which number was chosen, but still how do I
> > "jump" to the correct sub-program??? Even if I define the subprograms as
> > functions even, how do I jump to them???
>
> Calling a function is the same as jumping to it. Now there are all kinds
> of swank,y k-rad ways to solve your problem more efficiently or
> compactly then what I describe below, but I'm trying to keep it simple
> so you can learn at your own pace.
>
> def do_abc():
>     "does some stuff"
>     #...
>
> def do_def():
>     "does some stuff"
>     #...
>
> def do_ghi():
>     "does some stuff"
>     #...
>
> while 1:
>     command = raw_input("> ")
>     if command == "abc":
>         do_abc()
>     elif command == "def":
>         do_def()
>     elif command == "ghi":
>         do_ghi()
>     elif command == "quit":
>         break
>     else:
>         print "Unknown command"
>
> --
> Take a recipe. Leave a recipe.
> Python Cookbook!  http://www.ActiveState.com/pythoncookbook




More information about the Python-list mailing list