With the help of https://stackoverflow.com/a/22391379/9088305 and APT command line interface-like yes/no input? I have been able to build a little script that wait for a while but can be interrupted by pressing enter.
import sys, select, os, time
from distutils.util import strtobool
for i in range(100):
sys.stdout.write("\r")
sys.stdout.write("Wait for {:2d} seconds. Press Enter to continue".format(i))
sys.stdout.flush()
time.sleep(1)
if sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
check = 0
while not check:
userin = raw_input("Are you sure you want to continue? (yes/no)")
try:
bool = strtobool(userin)
if bool:
check = 1
break
else:
print("Let's continue then")
time.sleep(1)
break
except ValueError:
check = 0
print("Choose either yes or no, please")
if check == 1:
break
print "\nDone!"
However, upon execution, it will alway give the question once, with an ""Choose either yes or no, please" after that:
Are you sure you want to continue? (yes/no)Choose either yes or no, please Are you sure you want to continue? (yes/no)
I haven't been able to figure out why this is. Can someone help me out? So that I can just get "Are you sure you want to continue? (yes/no)" once and I can put in yes or no.
Thanks in advance!