Best method for a menu in a command line program?

braden faulkner brf256 at gmail.com
Wed Nov 3 21:19:42 EDT 2010


I'm using a menu for my command line app using this method.

choice = "foobar"
while choice != "q":
    if choice == "c":
        temp = input("Celsius temperature:")
        print "Fahrenheit:",celsius_to_fahrenheit(temp)
    elif choice == "f":
        temp = input("Fahrenheit temperature:")
        print "Celsius:",fahrenheit_to_celsius(temp)
    elif choice != "q":
        print_options()
    choice = raw_input("option:")

Just wondering if there is another or more efficient way I should be doing it?

Thanks
-- Braden Faulkner



More information about the Python-list mailing list