Getting information with minput
You can use the minput module to get input information from the user in an easy way.
minput has some input functions for your CLI based project, all based on mprint (and with markup support).
You can also edit the formatTable and colorTable using this module. And the mprint function is also imported together.
You can use minput by importing the module:
from mprint import minput
or
from mprint.minput import *
Functions
- [mquestion] (https://github.com/h0m3/python-mprint/wiki/Getting-information-with-minput#mquestion)
- [mpause] (https://github.com/h0m3/python-mprint/wiki/Getting-information-with-minput#mpause)
- [minput] (https://github.com/h0m3/python-mprint/wiki/Getting-information-with-minput#minput)
- [mnum_input] (https://github.com/h0m3/python-mprint/wiki/Getting-information-with-minput#mnum_input)
- [mis_number] (https://github.com/h0m3/python-mprint/wiki/Getting-information-with-minput#mis_number)
- [memail_input] (https://github.com/h0m3/python-mprint/wiki/Getting-information-with-minput#memail_input)
The mquestion input expect from the user an yes or no answer for an question, it returns true or false depending of what the user answered.
This function will raise an ValueError if the user type any odd values here (different from Yes, No, Yep, y, n...)
Argument | Description | Type |
---|---|---|
text | Question thay will be outputed to the user | str |
Optional Argument | Description | Type | Default |
---|---|---|---|
yes | Boolean to determine if the default answer is yes or no | boolean | True |
Return: (bool)
Response to the user, True
for yes and False
for no.
Example
minput.mquestion("Do you want to install this software?",True)
The mpause function pauses the screen with a message and wait for the user to press enter.
Optional Argument | Description | Type | Default |
---|---|---|---|
text | Text that will be displayed to the user | str | "Press enter to continue..." |
Return: (None)
Example
minput.mpause("Press enter...")
This function mimics Python input function (and raw_input for Python 2) with the difference that it portable to both Python 2 and Python 3 and has formatting instructions.
Optional Argument | Description | Type | Default |
---|---|---|---|
text | Text that will be displayed to the user | str | "" |
Return: (str)
Text that was input
Example
minput.minput("Type your name: ")
This function is similar to minput, but it only accept numbers. If you type something different from a number, it will raise an ValueError exception.
Optional Argument | Description | Type | Default |
---|---|---|---|
text | Text that will be displayed to the user | str | "" |
Return: (float)
Number that was input
Example
minput.mnum_input("Type your age: ")
This function is a simple filter to check if the input from the user is an email, if not, it will raise an ValueError exception.
Optional Argument | Description | Type | Default |
---|---|---|---|
text | Text that will be displayed to the user | str | "" |
Return: (str)
Email that was input
Example
minput.memail_input("Type your email address: ")
This function check if a value passed is a number (considering floating points with dot and negative numbers).
The function is_number is now deprecated and show a warning. Use this one
Argument | Description | Type |
---|---|---|
number | Value to evaluate | ? |
Return: (Bool)
if its number or not
Example
minput.is_number("5")