Query a user for input with a timeout.
Project description
Description
A tiny, simplistic little alternative to the standard Python input()-function allowing you to specify a timeout for the function.
pyTimedInput should work on both Windows and Linux, though no exceedingly extensive testing has been done and there might be bugs.
Install
$ pip3 install pyTimedInput
Usage
def timedInput(prompt="", timeOut=5, forcedTimeout=False, endCharacters=['\x1b', '\n', '\r'])
- The function timedInput() from pyTimedInput accepts the following parameters:
- prompt, str: a string to show the user as a prompt when waiting for input.
Defaults to an empty string.
- timeout: how many seconds to wait before timing out.
Defaults to 5 seconds.
- forcedTimeout: whether to wait for ‘timeout’ many seconds consecutively or simply time out regardless of user-input.
Defaults to False, ie. consecutive.
- endCharacters[]: what characters to consider as end-of-input.
Defaults to new-line, carrier-feed and ESC-key.
The function returns a string containing whatever user entered and a boolean whether the input timed out or not.
from pyTimedInput import timedInput
userText, timedOut = timedInput("Please, do enter something: ")
if(timedOut):
print("Timed out when waiting for input.")
print(f"User-input so far: '{userText}'")
else:
print(f"User-input: '{userText}'")
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyTimedInput-1.0.0.tar.gz
(3.6 kB
view hashes)
Built Distribution
Close
Hashes for pyTimedInput-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f117591eabdaa0f0137b1803160e2aa8c21694cf1dacca64734abd39347f8b79 |
|
MD5 | b5c96413eceeed5a6b13e89404d416cb |
|
BLAKE2b-256 | ac22d2d83b3999bbe80cbd0a58b68a24090d4566ebf0e13abb33a9e3ae4a434c |