Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import functools
- def my_decorator(func):
- @functools.wraps(func)
- def function_that_runs_func():
- print('In the decorator!')
- func()
- print("After decorator!")
- return function_that_runs_func
- @my_decorator
- def my_function():
- print("I am the function!")
- #my_function()
- def decorator_with_arguments(number):
- def my_decorator(func):
- @functools.wraps(func)
- def function_that_runs_func(*args, **kwargs):
- print('In the decorator!')
- if number == 56:
- print("Not running the function")
- else:
- func(*args, **kwargs)
- print("After decorator!")
- return function_that_runs_func
- return my_decorator
- @decorator_with_arguments(57)
- def my_function_too(x, y):
- print(x, y)
- my_function_too(57, 67)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement