Skip to main content

a few function to get clean inputs from a user

Project description

Terminal

Tests Coverage Code style: black PyPI version

How to install

Simply run

pip install inputmanager

How to use terminal

Content of the demo.py file :

# Packages
import inputmanager as im

# %% Read line function

# Open question
str_name = im.read_line('What is your name ?\n')
print(f'Hello, {str_name}.')

# Closed question
str_fruit = im.read_line('Do you prefere apples or pears ?\n', bl_case=False, lst_values=['Apples', 'Pears'])
print(f'I too like {str_fruit.lower()} :).')

# %% Yes or No questions

# By default recognize (yes, y, oui and o) as yes, and (no, n and non) as no.
im.read_yes_no('Proceed ? [y/n]\n')

# This can be changed
im.read_yes_no('Continuar ? [Si/No]\n', lst_pos_vals=['Si', 's'], lst_neg_vals=['No', 'n'])

# %% Read numeric

# Basic numeric read
int_res = im.read_numeric('Choose a numer :\n')
print(f'You chose {int_res}.')

# This function can be tweaked with some parameters :

int_res = im.read_numeric('Choose a number between 1 and 10 :\n', bl_int=True,
                          num_lb=1, num_ub=10, bl_inc_lb=True, bl_inc_ub=True)
print(f'You chose {int_res}.')

# %% Force read

# In order not to crash on a bad input, you can use the force_read function
int_res = im.force_read(im.read_numeric, 'Choose a number between 1 and 10 :\n', bl_int=True,
                        num_lb=1, num_ub=10, bl_inc_lb=True, bl_inc_ub=True)
print(f'You chose {int_res}.')

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

inputmanager-1.0.2.tar.gz (5.4 kB view details)

Uploaded Source

File details

Details for the file inputmanager-1.0.2.tar.gz.

File metadata

  • Download URL: inputmanager-1.0.2.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/3.10.0 pkginfo/1.8.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2

File hashes

Hashes for inputmanager-1.0.2.tar.gz
Algorithm Hash digest
SHA256 eafc8e0401fae0fc7141f48d0a152ddca4dc53866d4febcf91edc0bf104cc068
MD5 055e958c644b499c262f06715595296b
BLAKE2b-256 bbfe83202e0987c4a901113ea6d6f670987170b350a89faf9b346c00ace0e08d

See more details on using hashes here.

Supported by

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