class Attr(object):
def __init__(self,attrname,attrtype):
self.attrname=attrname
self.attrtype=attrtype
def __get__(self,instance,value):
return instance.__dict__[self.attrname]
def __set__(self,instance,value):
if not isinstance(value,self.attrtype):
raise TypeError("%s type error"%self.attrname)
instance.__dict__[self.attrname]=value
def __delete__(self,instance):
del instance.__dict__[self.attrname] class Person(object):
name=Attr("name",str)
age=Attr("age",int)
p=Person()
p.age=""

最新文章

  1. Format
  2. C/C++ 中判断某一文件或目录是否存在
  3. 页面Button/Link 传参数
  4. .net MVC 连接数据本地数据库三种方法
  5. [转]Oracle 分组聚合二种写法,listagg和wmsys.wm_concat
  6. 剑指offer系列26--正则表达式匹配
  7. 2434: [Noi2011]阿狸的打字机
  8. openstack theme topic
  9. ssh框架搭建时报错
  10. 深入理解viewport(转)
  11. c中const定义的问题
  12. 迁移git
  13. ORACLE获取SQL绑定变量值的方法总结
  14. 剑指offer编程题Java实现——面试题13在O(1)时间内删除链表节点
  15. VUE2 第五天学习--过渡效果
  16. Netty入门(2) - 核心概念
  17. caffe在solverstate的基础上继续训练模型
  18. MPT树详解
  19. Python中让MySQL查询结果返回字典类型的方法
  20. thinkphp AOP(面向切面编程)

热门文章

  1. php 通过类名获取类的文件地址
  2. 异步加载 Echarts图的数据
  3. 欧拉图 欧拉回路 欧拉通路 Euler
  4. python之IO model
  5. Section One
  6. Codeforces Round #196 (Div. 1) 题解
  7. 【置换群】poj3270 Cow Sorting
  8. Perl读写文件&字符串操作
  9. Java如何进行异常处理
  10. FTP客户端工具