Post

Python Decorators

调试代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import time

def login(func):
    def warpper(string):
        func(string)
        print('login')

    return warpper

def timeget(func):
    def war(string):
        print(time.time())
        func(string)

    return war
@login
@timeget

def f1(string):
    print('1.this is ', string)

@timeget
@login
def f2(string):
    print('2.this is ', string)

f1('asad')
f2('asad')

输出结果

1
2
3
4
5
6
1701069790.3941672
1.this is  asad
login
1701069790.3941672
2.this is  asad
login
This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.