{"id":187470,"date":"2020-11-06T18:35:03","date_gmt":"2020-11-06T10:35:03","guid":{"rendered":"http:\/\/4563.org\/?p=187470"},"modified":"2020-11-06T18:35:03","modified_gmt":"2020-11-06T10:35:03","slug":"%e5%8f%91%e7%8e%b0%e4%ba%86-python-%e4%b8%80%e4%b8%aa%e5%a5%87%e6%80%aa%e7%9a%84%e7%89%b9%e6%80%a7","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=187470","title":{"rendered":"\u53d1\u73b0\u4e86 Python \u4e00\u4e2a\u5947\u602a\u7684\u7279\u6027"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u53d1\u73b0\u4e86 Python \u4e00\u4e2a\u5947\u602a\u7684\u7279\u6027               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : AbcHiyi <\/span>  <span><i><\/i> 2<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u6b63\u5e38\u6765\u8bf4\u4f7f\u7528 bool \u51fd\u6570\u5224\u8bfb\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684\u5bf9\u8c61\u53ea\u8981\u5bf9\u8c61\u6ca1\u6709\u5b9e\u73b0 <strong>bool<\/strong> \u65b9\u6cd5\u56e0\u8be5\u662f\u9ed8\u8ba4\u4f5c\u4e3a true \u5904\u7406\u7684\u5427\u3002 \u4f46\u662f\u5947\u602a\u7684\u662f\u5728 3.8.5 \u7248\u672c\u4e2d\u6211\u81ea\u5b9a\u4e49\u7684\u4e00\u4e2a\u5bf9\u8c61\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u4f5c\u4e3a true \u67d0\u4e9b\u60c5\u51b5\u4e0b\u4f5c\u4e3a false \u5904\u7406\uff0c\u4f46\u662f\u6211\u786e\u5b9a\u6ca1\u6709\u5b9e\u73b0__bool__\u65b9\u6cd5.\u8fd9\u8ba9\u6211\u5f88\u8d39\u89e3\u3002\u4ed4\u7ec6\u89c2\u5bdf\u53d1\u73b0\uff0c\u8fd9\u4e2a\u5bf9\u8c61\u542b\u6709\u6709\u6548\u6570\u636e\u65f6\u4f5c\u4e3a true \u5904\u7406\uff0c\u4e0d\u542b\u6709\u65f6\u4f5c\u4e3a false \u3002\u8fd9\u8ba9\u6211\u5f88\u8d39\u89e3\u3002\u8c03\u7528\u6570\u636e\u6709\u5173\u7684\u81f3\u4e8e\u4e24\u4e2a\u65b9\u6cd5\uff0c\u4e00\u4e2a json \u65b9\u6cd5\uff0c\u4e00\u4e2a text \u65b9\u6cd5\u3002\u5728 josn \u5728\u4efb\u4f55\u60c5\u51b5\u4e0b\u90fd\u4e0d\u4f1a\u8f93\u51fa None\uff0ctext \u65b9\u6cd5\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u4f1a\u8f93\u51fa\u7a7a\u5b57\u7b26\u4e32\u3002\u4f46\u662f\u6d4b\u8bd5\u540e\u53d1\u73b0\u4e0e\u8fd9\u4e24\u4e2a\u65b9\u6cd5\u6ca1\u6709\u5173\u7cfb\u3002\u5b9e\u5728\u4e0d\u660e\u767d\u7a76\u7adf\u662f\u54ea\u91cc\u51fa\u4e86\u5dee\u9519\u3002<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>14<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4075727\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : askfermi <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             When this method is not defined, __len__() is called, if it is defined, and the object is considered true if its result is nonzero. If a class defines neither __len__() nor __bool__(), all its instances are considered true.<\/p>\n<p>https:\/\/docs.python.org\/3\/reference\/datamodel.html#object.__bool__                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4075728\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : AbcHiyi <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @askfermi \u8fd9\u5c31\u662f\u95ee\u9898\u6240\u5728\u4e86\uff0c\u6211\u65e2\u6ca1\u6709\u5b9a\u4e49 __bool__\u65b9\u6cd5\u4e5f\u6ca1\u6709\u5b9a\u4e49__len__\u65b9\u6cd5\uff0c\u4e5f\u6ca1\u6709\u5b9a\u4e49\u522b\u7684\u4e1c\u897f\u3002\u4e5f\u8bb8\u662f\u5176\u5b83\u95ee\u9898\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4075729\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : mec <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8d34\u4ee3\u7801\u5440                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4075730\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Kobayashi <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @mec \u8d34\u5565\u4ee3\u7801\u554a\u3002\u5927\u5bb6\u76f2\u8d4c\uff0c\u4eba\u4eba\u90fd\u6709\u673a\u4f1a\uff0c\u5c82\u4e0d\u7f8e\u54c9\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4075731\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : freakxx <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5148\u5410\u69fd\u4e0b\uff0c\u50cf\u8fd9\u6837\u7684\u6392\u7248\u548c\u95ee\u95ee\u9898\u7684\u624b\u6cd5\uff0c\u6211\u770b\u5230\u4e86\u4e00\u4e9b\u4e9b\u5582\u6211\u5403\u5c4e\u7684\u540c\u4e8b\u7684\u8eab\u5f71\u3002<br \/>\u51fa\u9519\u4e86\uff0c\u65e2\u4e0d\u7ed9 request\uff0c\u4e5f\u4e0d\u7ed9 response\uff0c\u4e5f\u4e0d\u7ed9\u7ec6\u8282\u3002<\/p>\n<p>\u53ef\u4ee5\u770b\u4e0b\u662f\u4e0d\u662f\u7ee7\u627f\u4e86\u57fa\u7840\u7c7b\u578b\uff0c\u6bd4\u5982 str\uff0c \u5bfc\u81f4\u7a7a\u503c\u7684\u65f6\u5019\u4e3a False<br \/>\u6bd4\u5982\u8fd9\u6837\u5199<br \/>class Value(str)                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4075732\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : laike9m <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8d34\u4ee3\u7801\uff0c\u8bf7                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4075733\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : AbcHiyi <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Kobayashi @laike9m @askfermi @freakxx \u62b1\u6b49\u62b1\u6b49 \u5fd8\u8bb0\u4e86 \u5927\u6982\u662f\u8fd9\u6837\u7684 \u6ca1\u6709\u7ee7\u627f<\/p>\n<p>class Semantic:<\/p>\n<p> @equal_language_check<br \/> def __init__(self, from_lang, to_lang, reper_text):<br \/> self.reper_text = reper_text<br \/> self.from_lang = from_lang<br \/> self.to_lang = to_lang<\/p>\n<p> template = Conf().template_of_semantic(<br \/> fromlang=from_lang,<br \/> text=reper_text,<br \/> tolang=to_lang,<br \/> )<\/p>\n<p> self.__data__ = requests.post(<br \/> **template<br \/> ).json()[0][&#8216;translations&#8217;]<\/p>\n<p> def __repr__(self):<br \/> return F'&#8221;{self.reper_text}&#8221;({self.from_lang})&#8211;&gt;({self.to_lang})&#8217;<\/p>\n<p> def text(self) -&gt; str:<br \/> data = self.json()[&#8216;semantic&#8217;]<br \/> text = &#8216;n&#8217;.join([F'{k}:{&#8220;,&#8221;.join(v)}&#8217; for k, v in data.items()])<br \/> return text<\/p>\n<p> def json(self) -&gt; dict:<br \/> semantics = {}<br \/> for i in self.__data__:<br \/> temp = []<br \/> for i_i in i[&#8216;backTranslations&#8217;]:<br \/> temp.append(i_i[&#8216;displayText&#8217;])<br \/> semantics[i[&#8216;displayTarget&#8217;]] = temp<br \/> return {<br \/> &#8216;from&#8217;: self.from_lang,<br \/> &#8216;semantic&#8217;: semantics,<br \/> &#8216;to&#8217;: self.to_lang<br \/> }                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4075734\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : AbcHiyi <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             class Semantic:<\/p>\n<p> @equal_language_check<br \/> def __init__(self, from_lang, to_lang, reper_text):<\/p>\n<p> def __repr__(self):<\/p>\n<p> def text(self) -&gt; str:<\/p>\n<p> def json(self) -&gt; dict:<\/p>\n<p>\u8fd9\u597d\u50cf\u6ca1\u6cd5\u5f04\u683c\u5f0f\uff0c\u5927\u81f4\u7ed3\u6784\u5c31\u662f\u8fd9\u6837\u7684                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4075735\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ericls <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             Python \u5f88\u52a8\u6001 anything is accessible at any time. \u4f60\u5f97\u8d34\u5b8c\u6574\u7684\u4ee3\u7801                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4075736\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : catxo <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             text \u8fd4\u56de\u7a7a\u5b57\u7b26<br \/>\u90a3\u5e94\u8be5\u53bb\u68c0\u67e5 self.json()[&#8216;semantic&#8217;] \u662f\u4e0d\u662f\u7a7a<br \/>\u6240\u4ee5\u5e94\u8be5\u68c0\u67e5 self.__data__\u662f\u4e0d\u662f\u7a7a<br \/>\u6240\u4ee5\u5e94\u8be5\u68c0\u67e5 requests.post \u8fd4\u56de\u4ec0\u4e48\u4e1c\u897f<br \/>\u4ece\u5934\u5230\u5c3e\u8ddf dunder method \u90fd\u6ca1\u6709\u5173\u7cfb                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4075737\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zone10 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u95ee\u9898\u7684\u9644\u5f55\u53ef\u4ee5\u7528 markdown \u683c\u5f0f\u7684, \u6015\u4f60\u4e0d\u77e5\u9053\u8ddf\u4f60\u63d0\u4e00\u5634, \u6ca1\u6392\u7248\u597d\u7684\u4ee3\u7801\u5c31\u61d2\u5f97\u770b\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4075738\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : freakxx <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @zone10 #11 <br \/>\u8fd9\u6837\u7684\u53e3\u6c14\uff0c\u663e\u5f97\u4f60\u80fd\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4075739\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : freakxx <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @AbcHiyi #8 <\/p>\n<p>\u611f\u89c9\u6ca1\u529e\u6cd5\u5224\u65ad\u51fa\u95ee\u9898\uff0c<\/p>\n<p>\u4f60\u53ef\u4ee5\u770b\u4e24\u4e2a\u5730\u65b9<br \/>\u4e00\u4e2a\u662f equal_language_check \u8fd9\u91cc\u6709\u6ca1\u5199\u4e86\u4ec0\u4e48\uff0c\u53ef\u80fd\u505a\u4e86\u4e00\u4e9b\u5c5e\u6027\u7684\u64cd\u4f5c<br \/>\u53e6\u5916\u5c31\u662f\u5728\u5bf9\u8c61\u8f93\u51fa\u7684\u5730\u65b9\uff0c\u770b\u4e0b__dir__ \u662f\u4e0d\u662f\u5305\u542b\u4e86 __bool__ \u6216 __len__ \u8fd9\u6837\u7684\u65b9\u6cd5                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4075740\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zone10 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @freakxx \u8d34\u4ee3\u7801\u8981\u6392\u597d\u7248\u662f\u7a0b\u5e8f\u5458\u7684\u57fa\u672c\u7d20\u517b, \u5bf9\u5927\u5bb6\u90fd\u597d, \u5f53\u7136\u4f60\u4e0d\u5728\u4e4e\u56f0\u96be\u4e50\u4e8e\u52a9\u4eba\u5f53\u6211\u6ca1\u8bf4                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u53d1\u73b0\u4e86 Python \u4e00\u4e2a\u5947\u602a\u7684\u7279&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\/187470"}],"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=187470"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/187470\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=187470"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=187470"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=187470"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}