X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=m_lib%2Ftty_menu.py;h=d6fd92069f1f20ebd8a2400721337a57fb5d27bd;hb=d1c355c4dbae68d29ed7e5b1e3dd5a77bdcbd2cb;hp=35ba43d1ba49d5db64763f6c0105c4e4ecb238fd;hpb=d7c459a9f979c4978cf07ff11056512a852fd61d;p=m_lib.git diff --git a/m_lib/tty_menu.py b/m_lib/tty_menu.py index 35ba43d..d6fd920 100755 --- a/m_lib/tty_menu.py +++ b/m_lib/tty_menu.py @@ -1,11 +1,14 @@ #! /usr/bin/env python -"""tty menus +"""tty menus""" - Written by Broytman, Mar 1998. Copyright (C) 1997 PhiloSoft Design. -""" +from __future__ import print_function -import string + +try: + raw_input +except NameError: # Python 3 + raw_input = input def hmenu(prompt, astring): @@ -28,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 @@ -43,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()