I want to write a decorator in python
: if a called function contains print
's, the decorator prints her name before this function being called. I'm familiar with decorators syntax, but I have a problem with checking if a function has print
within itself.
def preceeding_name(func):
@wraps(func)
def wrapper(*args, **kwargs):
if 'print' in func:
print(func.__name__)
result = func(*args, **kwargs)
return result
return wrapper
It is not necessary to check if the print
's from function will actually be called.