摘要: #内置方法实现迭代器协议 class test_iter: def __init__(self,n): self.n=n def __iter__(self): return self def __next__(self): if self.n == 100: raise StopIteration(... 阅读全文
posted @ 2019-03-06 11:16 献丑小角 阅读(126) 评论(0) 推荐(0) 编辑
摘要: #__format__ format_dic={ 'ymd':'{0.year}{0.mon}{0.day}', 'y-m-d':'{0.year}-{0.mon}-{0.day}', 'y:m:d':'{0.year}:{0.mon}:{0.day}' } class Data: def __init__(self,year,mon,day): self.year=ye... 阅读全文
posted @ 2019-03-06 11:15 献丑小角 阅读(297) 评论(0) 推荐(0) 编辑
摘要: #__getattribute__ class Foo: def __init__(self,x): self.x=x def __getattr__(self, item): print('执行__getattr__') def __getattribute__(self, item): print('执行__getatt... 阅读全文
posted @ 2019-03-06 11:12 献丑小角 阅读(294) 评论(0) 推荐(0) 编辑
摘要: #包装标准类型 class List(list): def append(self,p_object): if type(p_object) is str: #self.append(p_objec) #无限递归 super().append(p_object) #等价与list.append(p_object) d... 阅读全文
posted @ 2019-03-06 11:07 献丑小角 阅读(210) 评论(0) 推荐(0) 编辑