May 2018
Intermediate to advanced
380 pages
9h 37m
English
This walk through shows how to create a decorator that can be used to check arguments passed to a function. This can be handled in a number of different ways, such as if...else checks, assert statements, and so on, but, by using a decorator, we can use this code on any function that operates the same way:
def arg_check(func): def wrapper(num): if type(num) != int: raise TypeError("Argument is not an integer") elif num <= 0: raise ValueError("Argument is not ...