Input function - frPokerman/PythonFiles Wiki

Input(askMessage, errorMessage, authMode)

Rather than using the built-in function input() for specific expected values, the Input() function forces the user to type value of certain type.

To do so, the function will print the askMessage on each attempt, then if the user didn't entered a valid value, the errorMessage would be print right after, beginning a new attempt. When the user enter a valid value, the function stops and returns an object containing that value. To specify the valid values, use one of the selector (authMode) listed below:

Ask number in range :


  • "X..Y"
  • "X...Y"

Using one of these selectors will force the user to type an integer or float value that is greater or equal to X and lesser or equal to Y. Use two . dots to ask for an integer, or three to ask for a float. If the user enter a correct value, the function returns this value as an integer or a float, depending on the number of . dots in the selector.

Ask number over or under limit :


  • "X.."
  • "X..."
  • "..Y"
  • "...Y"

These selectors are similar to the previous ones, but with only one bound to the range. The number replacing X or Y is included in the range.

Ask number :


  • "*d"
  • "*f"

These selectors will make the function waiting for any integer ("*d"), or any float ("*f"), then returning the corresponding one when the entered value is valid.

Ask item in list :


  • "FOO/BAR"
  • "^foo/bar/baz/qux/quux/corge/grault/garply/waldo/fred/plugh/xyzzy/thud"

Using this selector will force the user to choose one of the element in list. Insert ^ at the beginning of the list to enable the case sensivity mode. Thus, the user needs to enter the full item and case sensitive. Otherwise, the user can type the name of an item as he want, omitting end of that item ("spam/eggs" ==> sp, SPAM, spa, e, E, EGG, EGGS ...).

This selector is the only one that return the expected value instead of the value that the user entered. This allows you to know exactly the answer of the user.

Ask alpha string :

Syntax: "*n"

This selector will return a string value. However, this string can not contains numbers, complexe characters ... but only letters without accent, spaces (ASCII : 32) and hyphens (ASCII : 45).

Ask path :


  • "path"
  • "dir"
  • "n|e"

These selectors will force the user to enter a valid path : an exising file ("path" and "n|e") or directory ("path" and "dir"). Unlike Unix-based-os' standards, the user has to enter the path without quotes, even if the path contains spaces.

The third of these selectors has a filter that allow you to accept only files with a certain name or a certain extension or both. To accept any file but no directory, use "*|*" instead. If the filter for the extension contains dots, the function will work as the extension would be a multi-extension : If the user types a correct file path, but with one extension (lorem.txt) wheareas the filter has multiple extensions ("*|"), the typed value will be processed as false (incorrect). On the other hand, if the given value has multiple extensions ( but the filter has only one ("*|txt"), the value will be processed as true (valid).