{"id":57049,"date":"2020-04-08T03:25:36","date_gmt":"2020-04-07T19:25:36","guid":{"rendered":"http:\/\/4563.org\/?p=57049"},"modified":"2020-04-08T03:25:36","modified_gmt":"2020-04-07T19:25:36","slug":"%e5%88%9d%e5%ad%a6python%ef%bc%8c%e9%81%87%e5%88%b0%e4%b8%80%e4%b8%aa%e9%97%ae%e9%a2%98%e6%90%9e%e4%b8%8d%e6%98%8e%e7%99%bd%ef%bc%8c%e6%b1%82%e5%a4%a7%e4%bd%ac%e8%a7%a3%e6%83%91","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=57049","title":{"rendered":"\u521d\u5b66python\uff0c\u9047\u5230\u4e00\u4e2a\u95ee\u9898\u641e\u4e0d\u660e\u767d\uff0c\u6c42\u5927\u4f6c\u89e3\u60d1"},"content":{"rendered":"\n<p>  \t\t\t\t\t<strong>nisekoi<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3>\u521d\u5b66python\uff0c\u9047\u5230\u4e00\u4e2a\u95ee\u9898\u641e\u4e0d\u660e\u767d\uff0c\u6c42\u5927\u4f6c\u89e3\u60d1<\/h3>\n<p>  \t\t \u672c\u5e16\u6700\u540e\u7531 nisekoi \u4e8e 2020-4-4 21:30 \u7f16\u8f91 <\/p>\n<p> \u4ee3\u7801\u662f\u8fd9\u6837\u7684 https:\/\/i.loli.net\/2020\/04\/04\/pIs5qelHtPfdxgT.png<br \/>  \u8fd9\u6837\u7684\u60c5\u51b5\u53ef\u4ee5\u6b63\u5e38\u8f93\u51fa\uff0c\u6ce8\u91ca\u4e0d\u77e5\u9053\u5199\u6ca1\u5199\u5bf9\uff0c\u5982\u679c\u9519\u4e86\u5e0c\u671b\u5927\u4f6c\u80fd\u6307\u51fa\u4e00\u4e0b\uff0c\u53ea\u5199\u4e86\u56db\u6b65\u662f\u56e0\u4e3a\u540e\u9762\u7684\u7406\u89e3\u4e0d\u4e86\u6267\u884c\u987a\u5e8f\u4e86\u3002<br \/>  \u540e\u9762\u5982\u679cB\u548cC\u5404\u8c03\u7528\u4e00\u6b21A\u7684init\u7684\u8bdd\uff0c\u5e94\u8be5\u4f1a\u8f93\u51fa\u4e24\u6b21enter A leave A\u554a\uff0c\u4e3a\u4ec0\u4e48\u53ea\u8f93\u51fa\u4e86\u4e00\u6b21<\/p>\n<p>  \u4f46\u662f\u5982\u679c\u628aB\u7c7b\u7684super().__init__() \u7ed9\u6ce8\u91ca\u6389\uff0cC\u5c31\u5b8c\u5168\u4e0d\u4f1a\u6267\u884c\u4e86\u3002\u8fd9\u662f\u4ec0\u4e48\u539f\u7406\u3002\u975e\u5e38\u56f0\u60d1\u3002\u6c42\u89e3\u3002\u7814\u7a76\u4e86\u4e00\u4e2a\u591a\u5c0f\u65f6\u4e86<br \/>  https:\/\/i.loli.net\/2020\/04\/04\/lYVIfPmX9S1p48h.png\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>\u6211\u662f\u4e00\u4e2a\u5927\u6c34\u602a<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t \u672c\u5e16\u6700\u540e\u7531 \u6211\u662f\u4e00\u4e2a\u5927\u6c34\u602a \u4e8e 2020-4-4 23:36 \u7f16\u8f91 <\/p>\n<p> \u4e00\u822c\u90fd\u662f\u7528Python\u5199\u5199\u7b80\u5355\u7684\u4ee3\u7801\uff0c\u5f88\u5c11\u6d89\u53caOOP\u7684\u590d\u6742\u90e8\u5206\u3002Python\u7684OOP\u57fa\u672c\u53ef\u4ee5\u770b\u4f5c\u9ed1\u76d2\uff0c\u65e0\u8bba\u662fJS\u7684\u4ee4\u4eba\u8bdf\u75c5\u7684\u539f\u578b\u94fe\u3001\u8fd8\u662fJava,C++\u7684\u7ecf\u5178\u7ee7\u627f\u6a21\u578b\uff0c\u90fd\u6709\u8db3\u591f\u7684\u8d44\u6599\u4f9b\u6240\u5b66\u8005\u53c2\u8003\uff0c\u6211\u6240\u63a5\u89e6\u7684Python\u5b66\u4e60\u8d44\u6599\u6ca1\u6709\u8be6\u7ec6\u7684\u4ecb\u7ecd\u5b83\u7684OOP\u6a21\u578b\uff0c\u57fa\u672c\u90fd\u662f\u70b9\u5230\u4e3a\u6b62\uff0c\u57fa\u7840\u5c31\u591f\u7528\u4e86\uff1a\u5355\u7ee7\u627f\u94fe\u7684\u7b80\u5355OOP\u6a21\u578b\u3002<\/p>\n<p>  \u591a\u91cd\u7ee7\u627f\u5c31\u662fOOP\u4e2d\u7684\u590d\u6742\u90e8\u5206\u3002<\/p>\n<p>  \u5c31`super().__init____()`\u6765\u8bf4\uff0c\u57fa\u4e8e\u6df1\u5ea6\u4f18\u5148\u641c\u7d22\u7684`mro`\u987a\u5e8f\u80fd\u89e3\u91ca\u7ee7\u627f\u7684\u65b9\u6cd5\u3001\u5c5e\u6027\u7684\u67e5\u627e\u987a\u5e8f\uff0c\u4f46\u65e0\u6cd5\u89e3\u91ca`__init__()`\u65b9\u6cd5\u7684\u6267\u884c\u673a\u5236\u3002<\/p>\n<p>  \u4e00\u4e2a\u53ef\u4ee5\u89e3\u91ca\u697c\u4e3b\u793a\u4f8b\u7684\u8bf4\u6cd5\u662f\u6839\u636e`super()`\u7684\u6587\u6863\uff1a<br \/>  &#8220;`<br \/>  Return a proxy object that delegates method calls to a parent or sibling class of type.<br \/>  &#8220;`<br \/>  \u6839\u636eD\u7c7b\u7684`mro`\u987a\u5e8f\uff1a<\/p>\n<p>  D\u7c7b\u7684super()\u5c06__init__()\u59d4\u6258\u7ed9\u4e86B\u7c7b<br \/>  B\u7c7b\u7684super()\u5c06__init__()\u59d4\u6258\u7ed9\u4e86C\u7c7b<br \/>  C\u7c7b\u7684super()\u5c06__init__()\u59d4\u6258\u7ed9\u4e86A\u7c7b<\/p>\n<p>  \uff08\u4ee5\u4e0a\u59d4\u6258\u53ea\u5728D\u7c7b\u7684__init__()\u6267\u884c\u73af\u5883\u4e0b\u6709\u6548\u3002\uff09<\/p>\n<p>  \u56e0\u6b64\uff1a<\/p>\n<p>  &#8211; A\u7c7b\u7684__init__()\u53ea\u4f1a\u6267\u884c\u4e00\u6b21<br \/>  &#8211; \u5f53\u6ce8\u91ca\u6389B\u7c7b\u4e2d\u7684super()\u540e\uff0cC\u7c7b\u7684__init__()\u5c31\u6ca1\u6709\u88ab\u8c03\u7528\uff0c\u6267\u884c\u5230B\u7c7b\u4e3a\u6b62<\/p>\n<p>  \u89e3\u91ca\u786e\u5b9e\u53ef\u4ee5\u8fd9\u6837\u8fdb\u884c\uff0c\u4f46\u7f3a\u4e4f\u4efb\u4f55\u6743\u5a01\u7684\u8d44\u6599\u6765\u4f50\u8bc1\u6211\u7684\u4ee5\u4e0a\u89e3\u91ca\uff0c\u56e0\u6b64\u6211\u59cb\u7ec8\u628aPython\u7684OOP\u770b\u4f5c\u9ed1\u76d2\uff0c\u4e5f\u4e0d\u4f1a\u82b1\u7cbe\u529b\u53bb\u7814\u7a76\uff0c\u56e0\u4e3a\u5bf9\u6211\u800c\u8a00\u6ca1\u6709\u610f\u4e49\u3002<\/p>\n<p>  \u5982\u679c\u771f\u60f3\u7814\u7a76\uff0c\u53ef\u4ee5\u53bb\u770b\u770bPython\u7684\u6e90\u7801\uff0c\u6bd5\u7adf\u5f00\u6e90\u3002\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>Ftsb<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t\u5f88\u7b80\u5355\u7684\u95ee\u9898\uff0c\u4e66\u6ca1\u4ed4\u7ec6\u770b<br \/>  https:\/\/www.runoob.com\/w3cnote\/python-extends-init.html\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>\u6715\u7684\u5927\u6e05\u5b8c\u4e86\uff1f<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t\u4eba\u751f\u82e6\u77ed\uff0c\u4f60\u7528python\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>mjsz<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\tsuper\u5c31\u662f\u4fdd\u8bc1\u7236\u7c7b\u53ea\u6267\u884c\u4e00\u6b21\u3002\u3002\u3002\u3002\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>518<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t\u56e0\u4e3a\u5982\u679cD\u7684\u4e24\u4e2a\u7236\u7c7b\u65b9\u6cd5\u540d\u76f8\u540c\uff0c\u5c31\u53ea\u7ee7\u627f\u7b2c\u4e00\u4e2a\u7c7b\u7684\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>likebeta<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\tpython 2.7\u7ecf\u5178\u7c7b &#8211; \u6df1\u5ea6\u4f18\u5148\u641c\u7d22\u57fa\u7c7b\u7ee7\u627f\u51fd\u6570\uff0c2.7\u7684\u65b0\u5f0f\u7c7b(\u7ee7\u627f\u81f3object)\u548c3.x &#8211; \u5e7f\u5ea6\u4f18\u5148\u641c\u7d22\u57fa\u7c7b\u7ee7\u627f\u51fd\u6570\uff0c\u57fa\u4e8e\u8fd9\u4e2a\u539f\u5219\u5982\u679c\u548c\u4f60\u60f3\u8981\u7684\u4e0d\u7b26\u5408\uff0c\u53ef\u4ee5\u624b\u52a8\u8c03\u7528\uff0c \u6216\u8005\u4f7f\u7528\u7ec4\u5408\uff0c \u6216\u8005\u518d\u5f80\u4e0a\u62bd\u8c61\u6210\u975e__init__\u65b9\u6cd5\u518d\u8c03\u7528\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>518<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\timport sys<\/p>\n<p>  class A():<br \/>  &nbsp; &nbsp; def __init__(self):<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;print(&quot;enter A&quot;)<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;print(&quot;leave A&quot;)<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;# print(self.__init__)<br \/>  &nbsp; &nbsp; def test(self):<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;print(&quot;test A&quot;)<\/p>\n<p>  class B(A):<br \/>  &nbsp; &nbsp; def __init__(self):<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;print(&quot;enter B&quot;)<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;super().__init__()<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;# super().test()<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;print(&quot;leave B&quot;)<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;print(super().__init__)<\/p>\n<p>  class C(A):<br \/>  &nbsp; &nbsp; def __init__(self):<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;print(&quot;enter C&quot;)<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;super().__init__()<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;# super().test()<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;print(&quot;leave C&quot;)<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;print(super().__init__)<\/p>\n<p>  class D(B,C):<br \/>  &nbsp; &nbsp; def __init__(self):<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;print(&quot;enter D&quot;)<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;super().__init__()<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;print(&quot;leave D&quot;)<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;print(super().__init__)<\/p>\n<p>  if __name__ == &#8216;__main__&#8217;:<br \/>  &nbsp; &nbsp; d = D()<br \/>  \u6253\u5370\u7684\u662f<br \/>  enter D<br \/>  enter B<br \/>  enter C<br \/>  enter A<br \/>  leave A<br \/>  &lt;bound method D.__init__ of &lt;__main__.D object at 0x117A9410&gt;&gt;<br \/>  leave C<br \/>  &lt;bound method A.__init__ of &lt;__main__.D object at 0x117A9410&gt;&gt;<br \/>  leave B<br \/>  &lt;bound method C.__init__ of &lt;__main__.D object at 0x117A9410&gt;&gt;<br \/>  leave D<br \/>  &lt;bound method B.__init__ of &lt;__main__.D object at 0x117A9410&gt;&gt;<br \/>  \u4f60\u4f53\u4f1a\u4e00\u4e0b\u628a\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>nisekoi<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t518 \u5927\u4f6c\u6709\u8bdd\u8bf4 : 2020-4-4 22:10<br \/>  \u6253\u5370\u7684\u662f<br \/>  enter D<br \/>  enter B<\/p>\n<p> \u5728\u53bb\u4e86\u89e3\u4e86\u4e00\u4e0b\u7ee7\u627f\u548csuper\u7684\u5de5\u4f5c\u539f\u7406\u540e\u7ec8\u4e8e\u641e\u660e\u767d\u4e86\u3002 \t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>\u6211\u662f\u4e00\u4e2a\u5927\u6c34\u602a<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t\u5df2\u7ecf\u66f4\u65b0\uff0c\u6b22\u8fce\u63a2\u8ba8\u3002\t\t\t  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>nisekoi \u5927\u4f6c\u6709\u8bdd\u8bf4 : \u521d&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/57049"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=57049"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/57049\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=57049"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=57049"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=57049"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}