Created
December 5, 2017 20:08
-
-
Save fwojciec/8e09e6d3bf0196b6ee40a83202505845 to your computer and use it in GitHub Desktop.
Python Decorator with Arguments Template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
def my_decorator_with_arguments(arg): | |
def my_decorator(func): | |
@functools.wraps | |
def function_that_runs_func(*args, **kwargs): | |
print('Before the decorated func!') | |
if arg: | |
print('Not running the func!') | |
else: | |
func(*args, **kwargs) | |
print('After the decorated func!') | |
return function_that_runs_func | |
return my_decorator | |
@my_decorator_with_arguments(True) | |
def my_function(): | |
print('I\'m the function') | |
my_function() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment