[Tutor] how to do "program chains"

alan.gauld@bt.com alan.gauld@bt.com
Mon, 15 Apr 2002 10:15:22 +0100


> i am used to working in an environment where the user signs on with a 
> password and is presented with a menu of choices of 
....
> with each choice a new program is called and executed. 

> how do i do this in python? example code somewhere?

There are various options.
Wholly Python:
1) write all the sub programs in separate modules.
2) write a module per menu and in each of these import 
   the required subprogram modules
[ You may like to use a dictionary to store the menu choice 
  to function lookups.... but its your choice]

Python menus only:
Write the menu handling code in Python then use the os.system() 
function to call external programs. When they complete they 
return to your python code.

Fancier Python:
Use the Python command module to implement a menu system 
which will be easy to move to a GUI framework in the future.

You can of course mix and match these approaches as you 
feel the need.

Oh and finally if you want to give the system a nice feel 
use the curses.getch() function(on Unix) or the msvcrt.getch() 
function(Windoze/DOS) to read the users menu selection 
- this means they don't have to hit ENTER after it and 
don't see the screen scroll up a line in the process. 
Looks much more professional. (If you are on Linux 
consider using the other curses stuff too)

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld