摘要:
重写方法的利器-superclass ilist(list): def __init__(self,dft=None,r=list()): super(ilist, self).__init__(r) #list.__init__(self,r) self.dft=dft def __getitem__(self,n): while len(self) >> 0[0, 0, 0, 0, 0]10由于刚开始不知道super,我是这样模拟x[n]的:class ilist(list): def __init__(self,d... 阅读全文
摘要:
这个方法比较好:class DataHolder: def __init__(self, value=None): self.value = value def set(self, value): self.value = value return value def get(self): return self.valuedh = DataHolder()if dh.set(something()): # do something with dh.valueelif dh.set(somethingelse()): ... 阅读全文