Skip to content

Instantly share code, notes, and snippets.

@fwojciec
Created December 5, 2017 20:08
Show Gist options
  • Save fwojciec/8e09e6d3bf0196b6ee40a83202505845 to your computer and use it in GitHub Desktop.
Save fwojciec/8e09e6d3bf0196b6ee40a83202505845 to your computer and use it in GitHub Desktop.
Python Decorator with Arguments Template
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