Chapter 12: Decorators and Context Managers
Decorators
def my_decorator(func):
def wrapper():
print("Before the function call")
func()
print("After the function call")
return wrapper
@my_decorator
def say_hello():
print("Hello!")
say_hello()
# Output:
# Before the function call
# Hello!
# After the function callBuilt-in Decorators
Context Managers
Contextlib Module
Combining Decorators and Context Managers
Exercises
Best Practices
Last updated