我想知道什麼時候使用什麼Python 3 super()。Python 3超級用法()
Help on class super in module builtins:
class super(object)
| super() -> same as super(__class__, <first argument>)
| super(type) -> unbound super object
| super(type, obj) -> bound super object; requires isinstance(obj, type)
| super(type, type2) -> bound super object; requires issubclass(type2, type)
直到現在我用super()
唯一沒有爭論和它的工作如預期(由Java開發者)。
問題:
- 什麼是 「綁定」 在這方面是什麼意思?
- 綁定和非綁定超級對象有什麼區別?
- 何時使用
super(type, obj)
以及何時super(type, type2)
? - 像
Mother.__init__(...)
那樣命名超類會更好嗎?
的問題是,特別是約Python3,但Simionato的博客文章系列是關於Python2,並註明*的好處是,你避免重複的名稱類,因爲該名稱隱藏在私有名稱的加密機制中。在Python3中這不再是真的,所以至少有一個優點是過時的。 – gerrit 2016-11-10 12:11:09