Skip to content

Instantly share code, notes, and snippets.

@FerdinaKusumah
Created August 31, 2021 04:12
Show Gist options
  • Save FerdinaKusumah/540fdbd9262c2089b21f5e0310afd630 to your computer and use it in GitHub Desktop.
Save FerdinaKusumah/540fdbd9262c2089b21f5e0310afd630 to your computer and use it in GitHub Desktop.
Python simple decorator
from functools import wraps
# Defining our custom decorator
def my_decorator(function):
@wraps(function)
def wrapper(a, b, c):
print("wrapper running!")
a += 1
b += 2
c += 3
return function(a, b, c)
return wrapper
# Using it to decorate a function
@my_decorator
def my_function(a, b, c):
print("my_function running!")
print(a, b, c)
my_function(a=1, b=2, c=3)
# wrapper running!
# my_function running!
# 2 4 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment