property自己实现
2024-09-05 09:07:39
# 先回顾一下
class Room:
def __init__(self,name,width,length):
self.name = name
self.width = width
self.length = length
@property
def area(self):
return self.width * self.length
r1 = Room('wang',100,100)
print(r1.area) class Lazyproperty:
def __init__(self,func):
self.func = func
def __get__(self,instance,owner):
print("我们自己定义的属性")
if instance is None:
return self
return self.func(instance)
class Room:
def __init__(self,name,width,length):
self.name = name
self.width = width
self.length = length
@Lazyproperty
# area = Lazyproperty(area)
# 现在area是一个类,而不是函数
def area(self):
# print(self.area)
return self.width * self.length
r1=Room('alex',1,1)
print(r1.area)
最新文章
- Windows下搭建Wordpress博客网站
- 【QUESTION】
- solr 3.5.0 与 tomcat 7.0.5 整合配置
- Microsoft Naive Bayes 算法——三国人物身份划分
- 为什么是 Cloud Service?
- 你是否还在质疑EF的性能
- 必备的 Java 参考资源列表(转)
- Web前端相关
- dmucs与distcc
- 实体框架 (EF) 入门 =>; 二、在全新的数据库中使用 Code First
- HDU 1043 Eight (A* + HASH + 康托展开)
- google perftools分析程序性能
- Delphi下创建异形窗体
- BZOJ 1691: [Usaco2007 Dec]挑剔的美食家( 平衡树 )
- shell初学
- openfec的学习笔记
- [SQL]SQL 执行顺序
- python--递归(附利用栈和队列模拟递归)
- ****** 三十四 ******、软设笔记【存储器系统】-Cache存储器
- Python+OpenCV图像处理(十五)—— 圆检测
热门文章
- Ubuntu16.04连接SSH出现 Server responded “Algorithm negotiation failed” 的解决方法
- php类知识---命名空间
- Python之exec()/compile()方法使用
- keras手写数字识别
- 坚果Pro2刷魔趣系统教程,刷回锤子系统教程
- http状态码301和302详解及区别——辛酸的探索之路
- 五、在事务中使用Mybatis缓存的那些坑
- python-pandas-1
- vue的通信方式(二)---祖父孙三个级别的之间的隔代通信
- Access denied for user 'ODBC'@'localhost' (using password: NO) 的解决方法