In this lesson, you’ll see a simpler and more common way to apply decorators to a function using the @
symbol.
You’ll see how to go from this:
def my_decorator(func):
def wrapper():
print("Something is happening before the function is called.")
func()
print("Something is happening after the function is called.")
return wrapper
def say_whee():
print("Whee!")
say_whee = my_decorator(say_whee)
To writing decorators this way:
def my_decorator(func):
def wrapper():
print("Something is happening before the function is called.")
func()
print("Something is happening after the function is called.")
return wrapper
@my_decorator
def say_whee():
print("Whee!")
TechBanerg on March 21, 2019
Chris, you are barely audible, could increase the volume of this lecture.