-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20220225.py
59 lines (46 loc) · 1.05 KB
/
20220225.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# -*- coding:UTF-8 -*-
# auther:drliu
# date:2022/2/25
# aim: 装饰器模式
import functools
def decorator_fuc2(origin_func):
'''
希望对函数进行加工
:param origin_func:
:return:
'''
@functools.wraps(origin_func)
def decorator_fuc(*args, **kwargs):
print(origin_func.__name__)
a = origin_func(*args, **kwargs)
return a
return decorator_fuc
@decorator_fuc2
def fuc1(sample):
print('sample:%s' % sample)
print('hello')
return 'hello', 'require'
def decorator_fuc1(origin_func):
'''
每次使用都要对函数进行加工,而不是一次性加工结束
:param origin_func:
:return:
'''
#a = origin_func()
#return a
a = origin_func()
return a
def main():
# print('origin_fuc')
# a = fuc1()
# print(a)
# print('decorator_fuc')
# b = decorator_fuc1(fuc1)
# print(b)
print('decorator_fuc')
#fuc2 = decorator_fuc2(fuc1)
a = fuc1('hhaa')
print(a)
print(fuc1.__name__)
if __name__ == '__main__':
main()