python: fix raw_input()/input() problem

This commit is contained in:
David Anderson 2020-10-12 14:50:59 -07:00
parent 43c98bff3d
commit 0e7dab4c2f
1 changed files with 10 additions and 6 deletions

View File

@ -64,19 +64,23 @@ def file_size(path):
f.seek(0,2) f.seek(0,2)
return f.tell() return f.tell()
# workaround for dubious function change in python3
#
from sys import version_info
def input_aux():
if version_info.major == 3:
return input()
return raw_input()
def query_yesno(str): def query_yesno(str):
'''Query user; default Yes''' '''Query user; default Yes'''
print (str, "[Y/n] ", end="") print (str, "[Y/n] ", end="")
try: input = raw_input return not input_aux().strip().lower().startswith('n')
except NameError: pass
return not input().strip().lower().startswith('n')
def query_noyes(str): def query_noyes(str):
'''Query user; default No''' '''Query user; default No'''
print (str, "[y/N] ", end="") print (str, "[y/N] ", end="")
try: input = raw_input return input_aux().strip().lower().startswith('y')
except NameError: pass
return input().strip().lower().startswith('y')
def get_output_file_path(filename): def get_output_file_path(filename):
""" Return the filename's path in the upload directory """ Return the filename's path in the upload directory