当前位置:网站首页>Multiple decorators decorate a function
Multiple decorators decorate a function
2022-06-25 16:10:00 【creedcc】
# !/usr/bin/env python
# -*- coding:utf-8 -*-
def wrapper1(func1): # func1 == func Primitive function
def inner1(*args, **kwargs):
print('wrapper1, before func')
ret1 = func1(*args, **kwargs)
print('wrapper1, after func')
return ret1
return inner1
def wrapper2(func2): # func2 = inner1
def inner2(*args, **kwargs):
print('wrapper2, before func')
ret2 = func2(*args, **kwargs)
print('wrapper2, after func')
return ret2
return inner2
@wrapper2 # The second step : func = wrapper2(func), Before executing the decorator, follow the first step func==inner1, Actuator finisher wrapper2 after ,func2==inner1, Sinister func==inner2
@wrapper1 # First step : func = wrapper1(func), Actuator finisher wrapper1, be func1 == func, Sinister func==inner1
def func():
print("Hello World!")
func() # The third step : func() == inner2() , Then execute the functions in turn according to the call , ( According to the second step :func==inner2)
The execution sequence is shown in the figure :
边栏推荐
- Consumer and producer cases of inter thread synchronization (condition variable)
- 原生js动态添加元素
- 面试官:你简历上说精通mysql,那你说下聚簇/联合/覆盖索引、回表、索引下推
- 揭秘GaussDB(for Redis):全面对比Codis
- Function and implementation of closures
- Leetcode topic [array]-34- find the first and last positions of elements in a sorted array
- Native JS dynamically add elements
- 一行代码可以做什么?
- error Parsing error: Unexpected reserved word ‘await‘.
- What is OA
猜你喜欢

Rapport de la main - d'oeuvre du Conseil de développement de l'aecg air32f103cbt6

商城风格也可以很多变,DIY了解一下!

DOM event flow, event delegate

Continuous integration of aspnetcore & cloud flow
Create raspberry PI image file of raspberry pie
Why does golang's modification of slice data affect the data of other slices?

Linux-MySQL数据库之高级SQL 语句一
Why is it said that restarting can solve 90% of the problems

DINO: DETR with Improved DeNoising Anchor Boxes for End-to-End Object Detection翻译

What can one line of code do?
随机推荐
Don't underestimate the integral mall, its role can be great!
The style of the mall can also change a lot. DIY can learn about it!
JS add custom attributes to elements
Optimization of lazyagg query rewriting in parsing data warehouse
Golang open source streaming media audio and video network transmission service -lal
揭秘GaussDB(for Redis):全面对比Codis
Check whether the port number is occupied
The release of autok3s v0.5.0 continues to be simple and friendly
Pytest test framework notes
Deep learning pytorch cifar10 dataset training "suggestions collection"
Most commonly used SQL statements
What are the reasons why the game industry needs high defense servers?
说下你对方法区演变过程和内部结构的理解
Mark the same items in the Li list in red
Continuous integration of aspnetcore & cloud flow
10款超牛Vim插件,爱不释手了
leetcode-8. 字符串转换整数 (atoi)
Error: homebrew core is a shallow clone
How to reload the win10 app store?
What exactly is a handler