当前位置:网站首页>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 :
边栏推荐
- 转换Cifar10数据集
- JS的注释
- The release of autok3s v0.5.0 continues to be simple and friendly
- Report on Hezhou air32f103cbt6 development board
- JS add custom attributes to elements
- Catheon gaming appointed mark Aubrey, former Asia Pacific head of Activision Blizzard, as CEO
- 原生js动态添加元素
- Jz-065 path in matrix
- Servlet details
- Overall MySQL architecture and statement execution process
猜你喜欢

Don't underestimate the integral mall, its role can be great!

Free books! AI across the Internet paints old photos. Here is a detailed tutorial!

不要小看了积分商城,它的作用可以很大!

error Parsing error: Unexpected reserved word ‘await‘.
Create raspberry PI image file of raspberry pie

Educational administration system development (php+mysql)

AutoK3s v0.5.0 发布 延续简约和友好

异步处理容易出错的点

合宙Air32F103CBT6开发板上手报告

Vscode有什么好用的插件?
随机推荐
Analysis of the concept of metacosmic system
Tensorflow loading cifar10 dataset
Load local cifar10 dataset
Geographic location data storage scheme - redis Geo
AutoK3s v0.5.0 发布 延续简约和友好
GO语言-锁操作
How to debug grpc by postman
赫尔辛基交通安全改善项目部署Velodyne Lidar智能基础设施解决方案
Mt60b1g16hc-48b:a micron memory particles FBGA code d8bnk[easy to understand]
基于神经标签搜索,中科院&微软亚研零样本多语言抽取式摘要入选ACL 2022
Golang uses Mongo driver operation - increase (Advanced)
说下你对方法区演变过程和内部结构的理解
Continuous integration of aspnetcore & cloud flow
元宇宙系统的概念解析
Describe your understanding of the evolution process and internal structure of the method area
Detailed explanation of IVX low code platform series -- Overview (I)
报错:homebrew-core is a shallow clone
MySQL installation tutorial
Prototype mode
Don't underestimate the integral mall, its role can be great!