class Lazyproperty:
def __init__(self, func):
self.func = func def __get__(self, instance, owner):
print('get')
# print(instance)
# print(owner)
if instance is None:
return self res = self.func(instance)
setattr(instance, self.func.__name__, res)
return res class Room:
def __init__(self, width, length):
self.width = width
self.length = length @Lazyproperty
def area(self):
return self.width * self.length @property
def area1(self):
return self.width * self.length r = Room(1, 2) # print(Room.area) print(r.area1) print(r.area)
print(r.__dict__)
print(r.area)

自定制property的更多相关文章

  1. 利用描述符自定制property

    利用描述符自定制property class Lazyproperty: def __init__(self,func): # print('==========>',func) self.fu ...

  2. python - 自定制property/property的延时计算

    自定制prooerty: #模拟@property 实现将类的函数属性变成类属性: #定义描述符 class msf(): def __init__(self,obj): self.obj = obj ...

  3. 利用类装饰器自定制property实现延迟计算

    class LazyProperty: ''' hello,我是非数据描述符(没有定义__set__,不然是大哥数据描述符了--!) ''' def __init__(self, func): pri ...

  4. 11.python描述符---类的装饰器---@property

    描述符1.描述符是什么:描述符本质就是一个新式类,在这个新式类中,至少实现了__get__(),__set__(),__delete__()这三个内置方法中的一个,描述符也被称为描述符协议(1):__ ...

  5. python基础----再看property、描述符(__get__,__set__,__delete__)

    一.再看property                                                                          一个静态属性property ...

  6. day28-python之property

    1.property用法 # class Goods: # def __init__(self): # # 原价 # self.original_price = 100 # # 折扣 # self.d ...

  7. Python学习第二十课——自定property and classmethod

    自定制property class Lazyproperty: def __init__(self,func): # print('==========>',func) self.func=fu ...

  8. python基础-面向对象进阶

    一.什么是反射 反射的概念是由Smith在1982年首次提出的,主要是指程序可以访问.检测和修改它本身状态或行为的一种能力(自省).这一概念的提出很快引发了计算机科学领域关于应用反射性的研究.它首先被 ...

  9. Python之路【第六篇】python基础 之面向对象进阶

    一 isinstance(obj,cls)和issubclass(sub,super) isinstance(obj,cls)检查是否obj是否是类 cls 的对象  和  issubclass(su ...

随机推荐

  1. BizTalk RosettaNet解决方案搭建

    contoso为证书颁发机构 分别在两台服务器中配置hosts 192.168.199.160 fabrikam 192.168.199.225 contoso 安装CA 控制面板,添加删除程序 打开 ...

  2. /linux-command-line-bash-shortcut-keys/

    https://www.howtogeek.com/howto/ubuntu/keyboard-shortcuts-for-bash-command-shell-for-ubuntu-debian-s ...

  3. eclipse is missing required source folder src/test/java

    原因:maven的bug,不兼容eclipse 解决方法:右击工程,选择run-->maven-->build重新构建工程,就解决了.

  4. windows下telnet命令不好用解决方案;

    1.按网上说的windows下打开功能,telnet客户端打钩是必须的: 2.如果还不行,找到telnet.exe:然后把此路径添加到环境变量path下即可: ps:telnet的退出:quit命令:

  5. 【iCore4 双核心板_ARM】例程三十三:SD_IAP_ARM实验——更新升级STM32

    实验现象及操作说明: 1.本例程共有两个代码包,APP和IAP,IAP程序功能实现将APP程序升级至STM32中. 2.直接上电或烧写程序将执行升级的APP应用程序. 3.按下按键上电或写程序将进行升 ...

  6. Vue:在vue-cli中使用Bootstrap

    一.安装jQuery Bootstrap需要依赖jQuery,所以引用Bootstrap之前要先引用jQuery,使用下面的命令引用jQuery: npm install jquery --save ...

  7. ABAP 文件选择框

    GUI_FILE_SAVE_DIALOG    CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_BROWSE         EXPORTING ...

  8. Kubernetes集群部署之五node节点部署

    Node节点是Kubernetes集群中的工作负载节点.每个node都会被master分配一些工作负载,每个node节点都运行以下关键服务进程.Kubelet :负责pod对应的容器的创建.启停等任务 ...

  9. BarTender中如何为称重设备设置秤显示?

    有关BarTender 2016表单中的称显示,前面都给大家介绍过了,包括秤显示属性设置,链接数据源属性设置等等.本文,将以图文并茂的方式,教大家如何为称重设备设置秤显示控件. 我们打开BarTend ...

  10. 根据xlsx模板生成excel数据文件发送邮件代码

    package mail; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundExcept ...