X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=m_lib%2Ftty_menu.py;h=06e756e157c78edf2883976da04629bc3576ccdb;hb=31d88f65f0df3d05f8a7c65b743f301b6c6985c2;hp=0c41c86f7bb5f921f3b7bebbee2fb41841f0da67;hpb=8d79317cdc8220ff3c2192e68fc1dfc749c3ea1c;p=m_lib.git diff --git a/m_lib/tty_menu.py b/m_lib/tty_menu.py index 0c41c86..06e756e 100755 --- a/m_lib/tty_menu.py +++ b/m_lib/tty_menu.py @@ -2,9 +2,16 @@ """tty menus""" +from __future__ import print_function import string +try: + raw_input +except NameError: # Python 3 + raw_input = input + + def hmenu(prompt, astring): """ Writes prompt and read result @@ -25,7 +32,7 @@ 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) @@ -40,14 +47,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()