(Newbie) Menu Not Functioning

mowestusa justnotworking at yahoo.com
Wed Sep 18 15:51:42 CEST 2002


I have created the following simple program.

import os

def menu():
    print "1. Copy Python Files from Office Computer to Floppy"
    print "2. Copy Python Files from Home Computer to Floppy"
    print "3. Copy Python Files from Floppy to Office Computer"
    print "4. Copy Python Files from Floppy to Home Computer"
    print "5. Quit"
    print

def officetoflop():
    os.system("xcopy C:\MyDocu~1\*.py a:")

def hometoflop():
    os.system("xcopy E:\MyDocu~1\*.py a:")

def floptooffice():
    os.system("xcopy a:\*.py C:\MyDocu~1")

def floptohome():
    os.system("xcopy a:\*.py E:\MyDocu~1")

menu_choice = 0

while menu_choice < 5:
    menu()
    menu_choice = input("Enter your selection:")
    if menu_choice == 1:
        officetoflop()
    elif menu_choice == 2:
        hometoflop()
    elif menu_choice == 3:
        floptooffice()
    elif menu_choice == 4:
        floptohome()
    else:
        print "Goodbye"

As you can see it is designed to simply keep all of my python files current
between home and work.  I know that there are probably better ways to write
this program by not using "os.system", but using "shutil" instead.  I tried
that first but I couldn't figure out how you could get just the ".py" files
from a directory, and then put into "shutil.copyfile".

The problem I have with my script is that I can only run it once.  For
example it lets me choose "1".  It copies all of the files onto the floppy
without problem.  Then the menu appears and the line "Enter your
selection:", but it doesn't allow me to make another choice.  I can't type
in any key from the keyboard at all.  The program seems to freeze.  Any
ideas why?  I tried using the same technique shown in the menu examples
given in the "Non-programmers Tutorial."

Thanks for the help.

mowestusa





More information about the Python-list mailing list