I’m making any program in Python 3.7.
I want to skip input
function after a specific time.
My code has the structure like the following rough code.
JavaScript
x
21
21
1
def functionA():
2
skip) (
3
4
5
def functionB():
6
skip) (
7
8
#TIMEOUT = 0.5
9
while True:
10
TXT = None
11
TXT = input("Enter: ")
12
13
if TXT == None:
14
functionA()
15
elif 'NAME' in TXT:
16
functionB()
17
elif TXT == 'EXIT':
18
break
19
else:
20
pass
21
I wanna skip the line TXT = input("Enter: ")
after TIMEOUT
time, 0.5 sec. How can I make the code of this flow the way I want?
Advertisement
Answer
You can use the inputimeout
module
You can install the module by running cmd and typing this command
JavaScript
1
2
1
pip install inputimeout
2
You can use it like this
JavaScript
1
6
1
from inputimeout import inputimeout, TimeoutOccurred
2
try:
3
var = inputimeout(prompt='>>', timeout=5)
4
except TimeoutOccurred:
5
var = ''
6
Steps to use
- Import the module in file
- start the try method
- make a variable and instead of input use
inputimeout
function and enter values as prompt=
andtimeout=
- In
except TimeoutOccurred:
enter the value of the var if timeout is occured