Python Decorator
Resources
- https://realpython.com/primer-on-python-decorators/
- https://www.programiz.com/python-programming/decorator
In Python, a decorator is a design pattern that allows you to modify the functionality of a function by wrapping it in another function.
The outer function is called the decorator, which takes the original function as an argument and returns a modified version of it.
def make_pretty(func):
def inner():
print("I got decorated")
func()
return inner
@make_pretty
def ordinary():
print("I am ordinary")
ordinary()
# Output:
# I got decorated
# I am ordinary
Is there a relationship between Python Decorators and the Decorator Design Pattern that I saw in C++?