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
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 in this example (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.2.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.2.tar.gz.
File metadata
- Download URL: upgradedinput-0.0.8.2.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 |
2473f16be730d4de77c8cd321d11efc6dab5777930a1a0f690cf1a3878c1a5ca
|
|
| MD5 |
34e725b7c7027321e1c942a2eb888de5
|
|
| BLAKE2b-256 |
da772c5326b27eb4c17306ce90f8cbc4c6aa9103eaee33f505dc080ee0a8263c
|
File details
Details for the file upgradedinput-0.0.8.2-py3-none-any.whl.
File metadata
- Download URL: upgradedinput-0.0.8.2-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 |
f6233abd336d6cd11c7746d036199b90a0705e2ae879e3a774712b20dc813c28
|
|
| MD5 |
9be7249669d51c4efd9b4d9b79a00e4e
|
|
| BLAKE2b-256 |
cd271ba8d51b779e3c74e46e9a3e9714ca0aded33704896d8ef53c6039d99827
|