不实例化一个 class 的时候使用它的property

 1 class A:
 2     @property
 3     def name(self):
 4         return "123"
 5 
 6 
 7 print(A.name)  # <property object at 0x10d54cf98>
 8 
 9 
10 class B(type):
11     @property
12     def name(cls):
13         return "123"
14 
15 
16 print(B.name)  # <property object at 0x10da69688>
17 
18 
19 class C(metaclass=B): ...
20 
21 
22 print(C.name)  # 123

 

posted @ 2018-07-26 11:40  两只老虎111  阅读(276)  评论(0编辑  收藏  举报