摘要:
#内置方法实现迭代器协议 class test_iter: def __init__(self,n): self.n=n def __iter__(self): return self def __next__(self): if self.n == 100: raise StopIteration(... 阅读全文
摘要:
#__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... 阅读全文
摘要:
#__getattribute__ class Foo: def __init__(self,x): self.x=x def __getattr__(self, item): print('执行__getattr__') def __getattribute__(self, item): print('执行__getatt... 阅读全文
摘要:
#包装标准类型 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... 阅读全文