python中super工作原理
2017-05-09 15:39
274 查看
python中可以通过super来调用父类的__init__函数,这个的好处是,当父类名称变化时,不需要进行子类代码更改,如下:
如果使用1,super方式调用父类__init__函数进行实例化,当父类A进行名字更改为B时,C类中不需要进行代码更改;
如果使用2,父类.__init__方式,当父类A进行名字更改为B时,C类中则需要进行代码更改,将2处的A.__init__(self) 改为B.__init__(self) 。
想要更好了解python中super的工作原理,可以看一下下面这两篇文章,两位楼主都总结的很好。
http://blog.csdn.net/seizef/article/details/5310107 http://www.cnblogs.com/lovemo1314/archive/2011/05/03/2035005.html
如果使用1,super方式调用父类__init__函数进行实例化,当父类A进行名字更改为B时,C类中不需要进行代码更改;
如果使用2,父类.__init__方式,当父类A进行名字更改为B时,C类中则需要进行代码更改,将2处的A.__init__(self) 改为B.__init__(self) 。
想要更好了解python中super的工作原理,可以看一下下面这两篇文章,两位楼主都总结的很好。
http://blog.csdn.net/seizef/article/details/5310107 http://www.cnblogs.com/lovemo1314/archive/2011/05/03/2035005.html
相关文章推荐
- 关于Python的super用法研究
- 关于Python的super用法研究
- python中super()详解
- How does Python's super() work with multiple inheritance?
- python的super缺陷,需要特别注意
- python简易版 super ping
- chapter9: python 类的方法,属性,迭代器(new[old]-type class,[un]bound method,super,protocol,property,iterators)
- 关于PYTHON里SUPER使用时报的typeerror错误 - dongua的日志 - 网易博客
- python invoke super parent method
- 关于Python的super用法研究(zt)
- Python内置函数super的不便之处
- [转]关于Python的super用法研究
- python super()
- python--super
- 关于PYTHON里SUPER使用时报的typeerror错误
- 关于Python的super用法研究(转载)
- python super()
- 关于Python的super用法研究
- python super
- python的super缺陷,需要特别注意