mirror of
https://github.com/clearml/clearml
synced 2025-02-07 21:33:25 +00:00
Fix user input wizard, support python 3.5 / 2.7
This commit is contained in:
parent
23394a265d
commit
0a5c10b4b0
@ -1,4 +1,3 @@
|
|||||||
import distutils
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
@ -53,11 +52,20 @@ def input_int(
|
|||||||
|
|
||||||
def input_bool(question, default=False):
|
def input_bool(question, default=False):
|
||||||
# type: (str, bool) -> bool
|
# 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:
|
while True:
|
||||||
try:
|
try:
|
||||||
response = input("{}: ".format(question)).lower()
|
response = input("{}: ".format(question)).lower()
|
||||||
if not response:
|
if not response:
|
||||||
return default
|
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:
|
except ValueError:
|
||||||
print("Invalid input: please enter yes or no")
|
print("Invalid input: please enter 'yes' or 'no'")
|
||||||
|
Loading…
Reference in New Issue
Block a user