Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def evaluate_error_flag(error_flag, output):
- """Decorator for processing error messages. Calls embedded within functions.
- :error_flag: True (error) or False (no error).
- :function: Either the error message (if error) or the data being validated (if no error).
- :returns: Validated data (if no error)
- """
- def evaluate_error(error_flag, output):
- func(error_flag, output)
- if error_flag:
- print(output)
- return output
- return evaluate_error
- @evaluate_error_flag
- def try_function(*args):
- """Wrapper uses a try statement and the wrapper to check for validity of statements.
- """
- def try_func(*args):
- try:
- return False, func(*args)
- except:
- return True, "Error in function {}.".format(str(function))
- return try_func
- @try_function
- def do_something(some_data, some_other_data):
- # some code
- pass
Add Comment
Please, Sign In to add comment