Skip to main content

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


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.4.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

upgradedinput-0.0.8.4-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file upgradedinput-0.0.8.4.tar.gz.

File metadata

  • Download URL: upgradedinput-0.0.8.4.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

Hashes for upgradedinput-0.0.8.4.tar.gz
Algorithm Hash digest
SHA256 2bf5e5990b5635125fdccad5e1e700e6ba46d69c2bc3eb3c3edbef6f531e894a
MD5 25ea8745e07f41896a2e095d96a29ae9
BLAKE2b-256 8a84a1a5a28690bb9e015808812c94a0c0748b6f012ca291487f11962b77f523

See more details on using hashes here.

File details

Details for the file upgradedinput-0.0.8.4-py3-none-any.whl.

File metadata

File hashes

Hashes for upgradedinput-0.0.8.4-py3-none-any.whl
Algorithm Hash digest
SHA256 eb72a62e842512b1217ed502c5fb635e1b687a4b9a9602eb1f13e7faa4609921
MD5 2903b7e1d30472b866ec0fafc7ac5ab2
BLAKE2b-256 c9ed4e3ed42410d41b4ab0ea50d9c212eb54b3b573029a0bfc3729a1461ba67d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page