Skip to content
This repository has been archived by the owner on Jun 19, 2018. It is now read-only.

Getting information with minput

Artur Paiva edited this page Dec 14, 2015 · 6 revisions

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

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)

mpause

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...")

minput

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: ")

mnum_input

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: ")

memail_input

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: ")

mis_number

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")