Fix user input wizard, support python 3.5 / 2.7

This commit is contained in:
allegroai 2020-07-30 15:08:27 +03:00
parent 23394a265d
commit 0a5c10b4b0

View File

@ -1,4 +1,3 @@
import distutils
from typing import Optional
@ -53,11 +52,20 @@ def input_int(
def input_bool(question, default=False):
# type: (str, bool) -> bool
"""
:param question: string to display
:param default: default boolean value
:return: return True if response is 'y'/'yes' 't'/'true' in input.lower()
"""
while True:
try:
response = input("{}: ".format(question)).lower()
if not response:
return default
return distutils.util.strtobool(response)
if response.startswith("y") or response.startswith("t"):
return True
if response.startswith("n") or response.startswith("f"):
return False
raise ValueError()
except ValueError:
print("Invalid input: please enter yes or no")
print("Invalid input: please enter 'yes' or 'no'")