{"id":111893,"date":"2020-05-30T22:55:38","date_gmt":"2020-05-30T14:55:38","guid":{"rendered":"http:\/\/4563.org\/?p=111893"},"modified":"2020-05-30T22:55:38","modified_gmt":"2020-05-30T14:55:38","slug":"%e5%a6%82%e4%bd%95%e5%88%a4%e6%96%ad-callable-%e9%9a%90%e5%90%ab%e5%8f%82%e6%95%b0-self-%e6%98%af%e8%87%aa%e5%b7%b1%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=111893","title":{"rendered":"\u5982\u4f55\u5224\u65ad callable \u9690\u542b\u53c2\u6570 self \u662f\u81ea\u5df1\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u5982\u4f55\u5224\u65ad callable \u9690\u542b\u53c2\u6570 self \u662f\u81ea\u5df1\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : anzu <\/span>  <span><i><\/i> 1<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<pre><code>class Worker:     def work(self, callback: Callable):         # \u5982\u4f55\u5224\u65ad callback \u9690\u542b\u53c2\u6570 self \u662f\u81ea\u5df1\uff1f         pass      def rest(self):         pass   def todo():     worker = Worker()     worker.work(worker.rest)   <\/code><\/pre>\n<\/p><\/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=\"1815917\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : anzu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u61c2\u4e86\uff0c\u8fd9\u6837<br \/> if getattr(callback, &#8216;__self__&#8217;, None) is self:<br \/> print(&#8216;callback is self&#8217;)                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1815918\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ranleng <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0d\u77e5\u9053\u5bf9\u4e0d\u5bf9.<\/p>\n<p>Worker().work \u7684 __class__ \u662f method<br \/>todo \u7684 __class__ \u662f function                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5224\u65ad callable \u9690\u542b\u53c2&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\/111893"}],"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=111893"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/111893\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=111893"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=111893"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=111893"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}