A better input() for python
Project description
UpgradedInput
A better, minimal input() wrapper for python
Features compared to python's default input()
- Supports hooks for functions (Before and after input, on exception and on runtime error)
- Supports automatic conversion with validation (With hooks too! Read docs)
How to use
Install the module
pip install UpgradedInput
Use the module Example:
from UpgradedInput import UpgradedInput, InputTypes
# initialize
inp = UpgradedInput()
# Example of hooks (All of them can be left at the dafult state (None))
def before():
print("Before!")
def after():
print("After!")
def exception():
print("Exception!")
def runtime_error():
print("Runtime error!")
def invalid_user_input(text):
print(text)
return None
# Initialize the hooks
inp.before_input_function = before
inp.after_input_function = after
inp.end_of_file_input_function = exception
inp.runtime_error_function = runtime_error # say we lost sys.stdin or something else that triggers a runtime error
inp.invalid_user_input_function = invalid_user_input
print(inp.input()) # final call to the wrapper
print(inp.input(prompt="insert text: ")) # supports prompt (from input)
# in case the automatic conversion fails, in this example it calls invalid_user_input
# which prints what the user typed, and returns None (REFER TO DOCUMENTATION!!!!!!!!)
print(inp.input(type=InputTypes.INTEGER)) # supports automatic conversion!
print(inp.input(type=InputTypes.FLOAT)) # floats
print(inp.input(type=InputTypes.BOOL)) # booleans
Testing
Run this command to install the testing suite:
pip install pytest pytest-ordering
Then simply run in the root directory:
pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
upgradedinput-0.0.8.5.tar.gz
(5.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file upgradedinput-0.0.8.5.tar.gz.
File metadata
- Download URL: upgradedinput-0.0.8.5.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c337b133304f85da0ad31c4f5f9e09114fbb0d4ab59de2fdb27d8b79629e6de3
|
|
| MD5 |
f9393f4b31fd90e9b3804933520bd46b
|
|
| BLAKE2b-256 |
f4591fa14ef09ce8c69536d9aa737054e4e1c21fcece9172a1792354fb7c5855
|
File details
Details for the file upgradedinput-0.0.8.5-py3-none-any.whl.
File metadata
- Download URL: upgradedinput-0.0.8.5-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ee609d42f3fe6aead3a12bd45b0e66bd8d2ed033912f7326444e4c5597fd724
|
|
| MD5 |
143dd172c9a5b29d79a4c2f7a40a4462
|
|
| BLAKE2b-256 |
b78059ce9f2af97fb4cc88c0dcd9dda4d94d262bc7f60cbbb5bd27299998a179
|