Skip to main content

Easily manage getting user inputs for all data types

Project description

EzInputs

EzInputs is built to get rid of the need to put while loops and try/except blocks around your type cast input() calls

The old way


    while True:

        num = input("Enter a number: ")

        try:

            num = int(num)

            break

        except ValueError:

            print("Invalid integer, try again")

The EzInputs way


    import ezinputs

    num = ezinputs.int_input()

Depending on how you measure it, ezinputs is about 10 times better!

Docs & Useage

Before we begin, these functions are all in the ezinputs.py file that ships in this package. Therein, full documentation is given for each function.

Primitive types

In this section we will look at the 4 primitive input types ezinputs has to offer.

All basic input types have two optional arguments;

prompt - the input prompt shown to the user (function-specific default)

error - the message displayed when an invalid value is entered (function-specific default)

Integer input

    >>> ezinputs.int_input()

    Enter an integer: 5

    (returns)
    5

Float input

    >>> ezinputs.float_input()

    Enter a float: 12.23

    (returns)
    12.23

Boolean input

    >>> ezinputs.bool_input()

    Enter boolean: True

    (returns)
    True

String input

Please just use the builtin python input(), this str_input() function is extremely redundant!


    >>> ezinputs.str_input()

    Enter a string: hello world!

    (returns)
    'hello world!'

Collection types

In this section we will look at the 4 collection input types ezinputs has to offer

The collection inputs have additional optional arguments on top of the besic input arguments;

astype - the datatype required for values (defaults to str)

count - the number of items to retrieve (defaults to 1)

List input

    >>> ezinputs.list_input(count=2, astype=int)

    Enter item 1: 5
    Enter item 2: 12

    (returns)
    [5, 12]

Set input

    >>> ezinputs.set_input(count=3, astype=float)

    Enter item 1: 7.6
    Enter item 2: 2
    Enter item 3: 4

    (returns)
    {2.0, 4.0, 7.6}

Tuple input

    >>> ezinputs.tuple_input(count=3, astype=bool)

    Enter item 1: a
    Enter item 2: 1
    Enter item 3: True

    (returns)
    (True, True, True)

Dictionary input

    >>> ezinputs.dict_input(count=3)

    Enter key 1: sugar
    Enter str value for sugar: 150g
    Enter key 2: flour
    Enter str value for flour: 400g
    Enter key 3: insert_cake_ingredient_here
    Enter str value for insert_cake_ingredient_here: some

    (returns)
    {'sugar': '150g', 'flour': '400g', 'insert_cake_ingredient_here': 'some'}

Author

Will Johnson

Discord: __wcj__#3111

Email: 277willjohnson@gmail.com

Website: https://heyteach.co.uk/

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

ezinputs-1.0.1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

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

ezinputs-1.0.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file ezinputs-1.0.1.tar.gz.

File metadata

  • Download URL: ezinputs-1.0.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.0 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.5

File hashes

Hashes for ezinputs-1.0.1.tar.gz
Algorithm Hash digest
SHA256 9e1dbf978b7cc8f58fbf043b74ceb7ece77d403a28362301c3f47e4dcd733f86
MD5 10312e8e057a0cb9336acf0b11674aa0
BLAKE2b-256 2630dc139eb57c3e707b63660eb85f44b0f400b72c243958bf6a3ad224701a57

See more details on using hashes here.

File details

Details for the file ezinputs-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: ezinputs-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.0 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.5

File hashes

Hashes for ezinputs-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6710e4842aeea0af1312f584eef7ee290203c87078de2a4cdc9241b207d56e51
MD5 629133819d6376e5df4acd745930cff6
BLAKE2b-256 086a68c51bc5d3c471a0e3ce6681317ab13754de2617e93625ed90214ad7bcfb

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