【Python学习之旅】---类的装饰器
#类的装饰原理,自定义一个高阶函数(把函数当做参数传入,返回值也是相同函数地址)def foo(bar): print(bar) bar.x=1 #操作Name的属性字典 bar.y=2 return bar@foo #Name=foo(Name)class Name: passprint(Name.__dict__) #输出Name的属性字典#一切皆对象,函数也有属性字典@foodef test(): print(‘test函数‘)test()print(test.__dict__)#执行结果:
<class ‘__main__.Name‘>
{‘__module__‘: ‘__main__‘, ‘__dict__‘: <attribute ‘__dict__‘ of ‘Name‘ objects>, ‘__weakref__‘: <attribute ‘__weakref__‘ of ‘Name‘ objects>, ‘__doc__‘: None, ‘x‘: 1, ‘y‘: 2}
<function test at 0x000002358FEC8EA0>
test函数
{‘x‘: 1, ‘y‘: 2}
相关推荐
FlySky 2020-10-16
FlySky 2020-09-29
bizercsdn 2020-09-17
python0 2020-08-16
chenzulong 2020-08-16
LULUBAO 2020-07-08
一叶不知秋 2020-06-28
yogoma 2020-06-14
周小董 2020-06-10
hongxiangping 2020-06-09
xmwang0 2020-06-08
JJandYY 2020-05-31
Andrewjdw 2020-05-27
wklken的笔记 2020-05-27
zhuquan0 2020-05-26
chongtianfeiyu 2020-05-20
cas的无名 2020-05-19
qianjq 2020-05-10