Package aerocalc :: Module val_input
[frames] | no frames]

Module val_input

source code

Validate user input against arbitrary criteria. Used in the interactive interface in other modules.

Functions
 
get_input(prompt, type, error_string, check_list=[], default='', **kwds)
Return user input after validating it.
source code
 
get_input2(prompt, conditions_any=[], conditions_all=[], debug=False)
Return user input, after validating it against arbitrary criteria.
source code
Function Details

get_input2(prompt, conditions_any=[], conditions_all=[], debug=False)

source code 

Return user input, after validating it against arbitrary criteria.

The user input must satisfy all conditions in conditions_all, and one or more of the conditions in conditions_any. Conditions_any is a list, with the first item the error string to display if none of the conditions are met. Conditions_all is a list of tuples, with each tuple having one condition + the associated error string to display to the user if the condition is not met.

The conditions will be inserted in 'if' statements, and must be written so that the 'if' statement will be true if the data is valid. E.g.

if a 'Q' is needed: 'X == "Q"'

Note 1: all data input by the user is seen as a string, even if numbers are entered. If the test is looking for an integer, write it as: 'int(X)'

Note 2: All tests are run inside 'try' statements, so exceptions will not cause problems. Any test that raises an exception is treated as a failed test.

Note 3: One idiosyncrasy of 'if' statements is that any statement that returns a "0" is treated as a False. Tests must be crafted so a pass does not return a '0'. E.g., if the test is intended to check that the data is a float, and a zero would be valid data, do not write the test as: 'float(X)', as 'if float("0"):' will not pass.