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.3.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.3-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: upgradedinput-0.0.8.3.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.3.tar.gz
Algorithm Hash digest
SHA256 6cc3fd924ab1571fa19cb261cd02521c784222a156f834c9cae57b478d76a462
MD5 3088df27eb8328103cfb7fb852dfda81
BLAKE2b-256 b9a2d61abd470ae87552b7b63e0197550d041edf39e55f69f756b89db9c8427e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for upgradedinput-0.0.8.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d63444230ace334a6b009f1d34f43f3eb06a7286d8b546ab3599c9f1202f3658
MD5 791f81fd5698069727237accc3bf417d
BLAKE2b-256 0e77285faf03fe545e4955b9bb2dd92c405a57467dbc2e4d8335d3a256ca7845

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