[Python] Simple Decorators
2021-01-02 13:29
标签:eps bsp decorator col with simple round UNC span Instead, Python allows you to use decorators in a simpler way with the More: https://realpython.com/primer-on-python-decorators/ [Python] Simple Decorators 标签:eps bsp decorator col with simple round UNC span 原文地址:https://www.cnblogs.com/Answer1215/p/12994456.htmldef 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)
>>> say_whee()
Something is happening before the function is called.
Whee!
Something is happening after the function is called.
@
symbol, sometimes called the “pie” syntax. The following example does the exact same thing as the first decorator example: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!")
上一篇:JavaScript常用工具类
下一篇:常用的在线工具网站
文章标题:[Python] Simple Decorators
文章链接:http://soscw.com/index.php/essay/39592.html