X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=m_lib%2Ftty_menu.py;h=d6fd92069f1f20ebd8a2400721337a57fb5d27bd;hb=4dedeb2041f8b9f7796991c2ff513f9e3aa8b386;hp=0c41c86f7bb5f921f3b7bebbee2fb41841f0da67;hpb=8d79317cdc8220ff3c2192e68fc1dfc749c3ea1c;p=m_lib.git diff --git a/m_lib/tty_menu.py b/m_lib/tty_menu.py index 0c41c86..d6fd920 100755 --- a/m_lib/tty_menu.py +++ b/m_lib/tty_menu.py @@ -2,7 +2,13 @@ """tty menus""" -import string +from __future__ import print_function + + +try: + raw_input +except NameError: # Python 3 + raw_input = input def hmenu(prompt, astring): @@ -25,14 +31,14 @@ def vmenu(item_list, prompt, format = "%d. %s"): returns selected number. Returns -1, if user enter non-numeric string. """ for i in range(len(item_list)): - print format % (i, item_list[i]) + print(format % (i, item_list[i])) print result = raw_input(prompt) try: - result = string.atoi(result) - except string.atoi_error: + result = int(result) + except ValueError: result = -1 return result @@ -40,14 +46,14 @@ def vmenu(item_list, prompt, format = "%d. %s"): def test(): result = hmenu("Select: d)aily, w)eekly, m)onthly, c)ancel: ", "dwmc") - print "Answer is '%s'\n" % result + print("Answer is '%s'\n" % result) os_list = ["DOS", "Windows", "UNIX"] result = vmenu(os_list, "Select OS: ") if 0 <= result < len(os_list): - print "Answer is '%s'\n" % os_list[result] + print("Answer is '%s'\n" % os_list[result]) else: - print "Wrong selection" + print("Wrong selection") if __name__ == "__main__": test()