摘要: 一、isinstance(obj,cls)检查obj是否是类cls的对象 二、__setitem__、__getitem__、__delitem__:只能用字典的方式,才能触发 与__getattr__、方式不同,效果一样 三、str与repr repr:如果找不到__str__,就会去找__rep 阅读全文
posted @ 2019-03-27 17:06 wind_y 阅读(172) 评论(0) 推荐(0) 编辑
摘要: getattr(object,name[,default]) 获取对象object的属性或者方法,如果存在打印出来,如果不存在,打印出默认值,默认值可选 注意:name必须用“”引起来 方法拿到的是地址,加()即可运行函数 阅读全文
posted @ 2019-03-27 15:24 wind_y 阅读(1818) 评论(0) 推荐(1) 编辑
摘要: 定制自己的数据类型: class List(list): def append(self, p_object): if type(p_object) is str: # self.append(p_object) #会无限循环 super().append(p_object) #调用父类的appen 阅读全文
posted @ 2019-03-27 15:15 wind_y 阅读(194) 评论(0) 推荐(0) 编辑
摘要: 注意:跟类无关,只对类的实例起作用 1.__getattr__ 当_get_getattr__与__getattribute__一起出现时: 当属性存在时,触发__getattribute__ 当属性不存在时,也是先触发__getattribute__,然后通过语句:raise AttributeE 阅读全文
posted @ 2019-03-27 10:35 wind_y 阅读(127) 评论(0) 推荐(0) 编辑