__new__ 实例化子类
来源:互联网 发布:谁搞过自己的妈妈知乎 编辑:程序博客网 时间:2024/05/19 17:50
class Foo(object): def __init__(self, name): self.name = name print "======================================" super(Foo, self).__init__() def __new__(cls, *args, **kwargs): return super(Foo, cls).__new__(Bar) def func1(self): print "111111111111111111111"*10 def func2(self): print "222222222222222222222"*10 self.func3();class Bar(Foo): def __init__(self, *args, **kwargs): import pdb; pdb.set_trace(); print args print kwargs def __new__(cls, *args, **kwargs): import pdb; pdb.set_trace(); super(Bar, cls).__new__(*args, **kwargs) def func3(self): print "333333333333333333333" def func4(self): self.func1(); print "444444444444444444444"if __name__ == '__main__': import pdb; pdb.set_trace(); f = Foo() f.func2() f.func3() f.func4()
class Foo(object): def __init__(self, name): self.name = name print "======================================" super(Foo, self).__init__() def __new__(cls, *args, **kwargs): return super(Foo, cls).__new__(Bar) def func1(self): print "111111111111111111111"*10 def func2(self): print "222222222222222222222"*10 self.func3();class Bar(Foo): def __init__(self, *args, **kwargs): import pdb; pdb.set_trace(); print args print kwargs def __new__(cls, *args, **kwargs): import pdb; pdb.set_trace(); super(Bar, cls).__new__(*args, **kwargs) def func3(self): print "333333333333333333333" def func4(self): self.func1(); print "444444444444444444444"if __name__ == '__main__': import pdb; pdb.set_trace(); f = Foo() f.func2() f.func3() f.func4()
阅读全文
0 0
- __new__ 实例化子类
- Python 之 __new__() 方法与实例化
- Python 之 __new__() 方法与实例化
- Python 之 __new__() 方法与实例化
- Python 之 __new__() 方法与实例化
- Python 之 __new__() 方法与实例化
- python之__new__方法与实例化
- [Python] Python 之 __new__() 方法与实例化
- [Python] Python 之 __new__() 方法与实例化
- [Python] Python 之 __new__() 方法与实例化
- Python中__new__()方法的使用和实例化
- 子类实例化过程
- 子类实例化
- 子类实例化顺序
- 关于子类实例化
- 窗口子类化-实例应用
- 子类的实例化过程
- super子类实例化过程
- eclipse中去掉js引入报错、红叉问题
- XXX cannot be resolved to a type
- ffmpeg录制usb摄像头和alsa音频出现ALSA buffer xrun.
- 第十一周 项目4 — 利用遍历思想求解图问题(7)
- spring boot 打包从jar转换成war
- __new__ 实例化子类
- python tornado使用流生成图片
- 思维导图之鱼骨图的实际应用
- 解读flow-guided feature aggregation for video object detection
- iphoneX兼容记录
- 关于--Error: User Command terminated, Exit-Code = 1解决办法
- 检查Logic Java 课程最近一次考试。如果全部没有通过考试(60分及格),则认为本次考试偏难,计算该次考试平均分加5分。
- SpringBoot的文件下载
- VR