{"id":320278,"date":"2021-02-05T03:43:56","date_gmt":"2021-02-04T19:43:56","guid":{"rendered":"http:\/\/4563.org\/?p=320278"},"modified":"2021-02-05T03:43:56","modified_gmt":"2021-02-04T19:43:56","slug":"python-reload-%e5%af%b9%e5%8d%95%e4%be%8b%e5%af%b9%e8%b1%a1%e7%9a%84%e5%bd%b1%e5%93%8d","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=320278","title":{"rendered":"Python reload \u5bf9\u5355\u4f8b\u5bf9\u8c61\u7684\u5f71\u54cd"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Python reload \u5bf9\u5355\u4f8b\u5bf9\u8c61\u7684\u5f71\u54cd               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : towry <\/span>  <span><i><\/i> 8<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\">                        \u5047\u5982\u5728 python \u4e2d\u4f7f\u7528\u4e86\u5355\u4f8b\u6a21\u5f0f\uff0c\u7ef4\u62a4\u4e86\u4e00\u4e2a\u53d8\u91cf\uff0c\u90a3\u4e48\u5728\u6a21\u5757\u88ab reload \u540e\uff0c\u8fd9\u4e2a\u53d8\u91cf\u4f1a\u53d8\u5417\uff1f      <\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>2<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5071190\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : hareandlion <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u8981\u770b\u5355\u4f8b\u6a21\u5f0f\u7684\u5bf9\u8c61\u662f\u5728\u54ea\u91cc\u521b\u5efa\u7684\u4e86\u5427\uff0c\u4e00\u822c\u60c5\u51b5\u4e0b\u5355\u4f8b\u6a21\u5f0f\u6240\u5f15\u7528\u7684\u5bf9\u8c61\u662f\u5728\u88ab reload \u7684 module \u91cc\u521d\u59cb\u5316\u7684\uff0c\u90a3 reload \u4f1a\u521b\u5efa\u65b0\u7684\u5bf9\u8c61\uff0c\u800c\u5982\u679c\u5355\u4f8b\u5f15\u7528\u7684\u662f\u5b58\u5728\u5185\u5b58\u91cc\u7c7b\u4f3c int \u7684\u57fa\u672c\u7c7b\u578b\u5bf9\u8c61\uff0creload \u4e4b\u540e\u4f9d\u7136\u4f1a\u5f15\u7528\u539f\u672c\u7684\u5bf9\u8c61\u3002<\/p>\n<p>si_cls.py<br \/>&#8220;`<br \/>#!\/bin\/python<br \/># coding: utf-8<\/p>\n<p>ph = {&#8216;ab&#8217;: 2}<br \/># ph = 32<\/p>\n<p>class SI:<br \/> def __new__(cls, *args, **kwargs):<br \/> return ph<\/p>\n<p> def id(self):<br \/> return id(self)<\/p>\n<p>si_instance = SI()<br \/>&#8220;`<\/p>\n<p>test.py<br \/>&#8220;`<br \/>#!\/bin\/python<br \/># coding: utf-8<\/p>\n<p>import si_cls<br \/>from importlib import reload<\/p>\n<p>s1 = si_cls.SI()<br \/>s2 = si_cls.SI()<\/p>\n<p>print(f&#8217;id(s1)={id(s1)}, id(s2)={id(s2)}, id(si_instance)={id(si_cls.si_instance)}&#8217;)<\/p>\n<p>reload(si_cls)<\/p>\n<p>s1 = si_cls.SI()<br \/>s2 = si_cls.SI()<\/p>\n<p>print(f&#8217;id(s1)={id(s1)}, id(s2)={id(s2)}, id(si_instance)={id(si_cls.si_instance)}&#8217;)<\/p>\n<p>&#8220;`                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5071191\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : abersheeran <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5de7\u4e86\u3002\u4ee5\u524d\u7814\u7a76\u8fc7\u76f8\u5173\u7684\u4e1c\u897f\u5199\u4e86\u4e00\u7bc7\u535a\u5ba2\u7559\u4f5c\u8bb0\u5f55\u3002\u4f60\u770b\u770b\u5427\u3002https:\/\/aber.sh\/articles\/Python-Reload\/<\/p>\n<p>\u5f53\u65f6\u5199\u7684\u53ef\u80fd\u6bd4\u8f83\u4e71\uff0c\u5982\u679c\u6709\u6ca1\u770b\u61c2\u7684\u90e8\u5206\u53ef\u4ee5\u6587\u7ae0\u4e0b\u53d1\u8bc4\u8bba\u95ee\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Python reload \u5bf9\u5355\u4f8b&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\/320278"}],"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=320278"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/320278\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=320278"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=320278"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=320278"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}