A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2001-April/081247.html below:

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

In the Absence of a GoTo Statement: Newbie needs menu-launcher to choose amongst sub-programs In the Absence of a GoTo Statement: Newbie needs menu-launcher to choose amongst sub-programsBob Kline bkline at rksystems.com
Fri Apr 13 16:14:10 EDT 2001
On Fri, 13 Apr 2001, 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.

Even more trivial without them.

import sys
def a(): print "processing using algorithm A"
def b(): print "processing using algorithm B"
def c(): print "processing using algorithm C"
def quit(): sys.exit(0)

cmds = { "A": a, "B": b, "C": c, "exit": quit }

while 1:
    cmd = raw_input("> ")
    if cmd not in cmds.keys(): print "unknown command %s" % cmd
    else: cmds[cmd]()

-- 
Bob Kline
mailto:bkline at rksystems.com
http://www.rksystems.com



More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4