Property属性-smd贴片型led的封装史上最全

时间:2021-06-08 13:34:52
【文件属性】:
文件名称:Property属性-smd贴片型led的封装史上最全
文件大小:7.14MB
文件格式:PDF
更新时间:2021-06-08 13:34:52
Python 计算 机器学习 数据可视化 6.4 Property属性 标准的Python提供了Property功能,Property看起来像对象的一个成员变量,但是在获取它的值或者 给它赋值的时候实际上是调用了相应的函数。Traits也提供了类似的功能。让我们先来看一个例子: 1 # -*- coding: utf-8 -*- 2 # filename: traits_property.py 3 from enthought.traits.api import HasTraits, Float, Property, cached_property 4 5 class Rectangle(HasTraits): 6 width = Float(1.0) 7 height = Float(2.0) 8 9 #area是一个属性,当width,height的值变化时,它对应的_get_area函数将被调用 10 area = Property(depends_on=['width', 'height']) 11 12 # 通过cached_property decorator缓存_get_area函数的输出 88 第 6 章 Traits-为Python添加类型定义

网友评论