{"id":525,"date":"2019-08-28T18:06:38","date_gmt":"2019-08-28T10:06:38","guid":{"rendered":"http:\/\/vip.fxxkpython.com\/?p=525"},"modified":"2020-07-08T16:46:59","modified_gmt":"2020-07-08T08:46:59","slug":"python%e5%bf%ab%e9%80%9f%e5%85%a5%e9%97%a8-python%e4%b8%ad%e9%a2%91%e7%b9%81%e4%bd%bf%e7%94%a8%e5%88%b0%e7%9a%84%e8%af%ad%e5%8f%a5%ef%bc%9a%e7%89%9b%e9%80%bc%e7%9a%84-with-%e8%af%ad%e5%8f%a5","status":"publish","type":"post","link":"https:\/\/vip.fxxkpython.com\/?p=525","title":{"rendered":"Python\u5feb\u901f\u5165\u95e8 | python\u4e2d\u9891\u7e41\u4f7f\u7528\u5230\u7684\u8bed\u53e5\uff1a\u725b\u903c\u7684 with \u8bed\u53e5"},"content":{"rendered":"\n<p>\u63a5\u7740\u4e0a\u7bc7\uff0c\u6211\u4eec\u7ee7\u7eed\u6765\u8bf4\u8bf4 Python \u4e2d\u5e38\u5e38\u4f1a\u7528\u5230\u7684\u8bed\u53e5\u3002<\/p>\n\n\n\n<h2>with<\/h2>\n\n\n\n<p>with \u8bed\u53e5\u53ef\u4ee5\u8bf4\u662f Python \u4e2d \u201c\u4eba\u751f\u82e6\u77ed\uff0c\u6211\u7528 Python\u201d \u7684\u4ee3\u8868\u4e4b\u4e00\uff0c\u5b83\u53ef\u4ee5\u4f7f\u5f97\u6211\u4eec\u5728\u7f16\u5199\u4ee3\u7801\u7684\u65f6\u5019\u975e\u5e38\u7b80\u77ed\uff0c\u4e14\u884c\u4e4b\u6709\u6548\u3002<\/p>\n\n\n\n<p>\u4e3e\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0c<div style=\"text-align:center;border:1px dashed #FF9A9A;padding:8px;margin:10px auto;color:#FF6666;\">\u672c\u6587\u9690\u85cf\u5185\u5bb9 <a href=\"https:\/\/vip.fxxkpython.com\/wp-login.php?redirect_to=https%3A%2F%2Fvip.fxxkpython.com%2F%3Fp%3D525\">\u767b\u9646<\/a> \u540e\u624d\u53ef\u4ee5\u6d4f\u89c8<\/div>ok\uff0c\u4ee5\u4e0a\u5c31\u662f\u6211\u8981\u8ddf\u4f60\u8bf4\u7684\uff0cwith \u8bed\u53e5\u7684\u5de5\u4f5c\u65b9\u5f0f\uff0c\u7b80\u5355\u70b9\u8bf4\uff0center \u65b9\u6cd5\u505a\u4e00\u4e9b\u521d\u59cb\u5316\u64cd\u4f5c\uff0cexit \u505a\u4e00\u4e9b\u64e6\u5c41\u80a1\u7684\u64cd\u4f5c\u3002\u603b\u7ed3\u4e00\u4e0b\u5c31\u662f\uff1a<\/p>\n\n\n\n<p>1.\u901a\u8fc7 with \u8bed\u53e5\u53ef\u4ee5\u5f97\u5230\u4e00\u4e2a\u4e0a\u4e0b\u6587\u7ba1\u7406\u5668<\/p>\n\n\n\n<p>2.\u6267\u884c\u5bf9\u8c61<\/p>\n\n\n\n<p>3.\u52a0\u8f7d&nbsp;__enter__ \u65b9\u6cd5<\/p>\n\n\n\n<p>4.\u52a0\u8f7d&nbsp;__exit__ \u65b9\u6cd5<\/p>\n\n\n\n<p>5.\u6267\u884c&nbsp;__enter__\uff0c<br><\/p>\n\n\n\n<p>6.as&nbsp;\u53ef\u4ee5\u5f97\u5230 enter&nbsp;\u7684\u8fd4\u56de\u503c<\/p>\n\n\n\n<p>7.\u62ff\u5230\u5bf9\u8c61\u6267\u884c\u76f8\u5173\u64cd\u4f5c<br><\/p>\n\n\n\n<p>8.\u6267\u884c\u5b8c\u4e86\u4e4b\u540e\u8c03\u7528&nbsp;__exit__&nbsp;\u65b9\u6cd5<br><\/p>\n\n\n\n<p>9.\u5982\u679c\u9047\u5230\u5f02\u5e38\uff0c__exit__ \u53ef\u4ee5\u83b7\u53d6\u5230\u5f02\u5e38\u4fe1\u606f<br><\/p>\n\n\n\n<p>10.\u5728 __exit__ \u4e2d\u5904\u7406\u5f02\u5e38\uff0c\u8fd4\u56de True<\/p>\n\n\n\n<p>11.\u7ee7\u7eed\u6267\u884c&nbsp;with \u540e\u9762\u7684\u8bed\u53e5\u3002<\/p>\n\n\n\n<p>\u90a3\u4e48\u73b0\u5728\u7684\u4f60\uff0c\u80fd\u5426\u5199\u4e00\u4e2a with \u8bed\u53e5\u7684\u4f8b\u5b50\uff0c\u52a0\u6df1\u4e0b\u81ea\u5df1\u5bf9\u5b83\u7684\u8ba4\u8bc6\u4e86\u5462\uff1f<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a5\u7740\u4e0a\u7bc7\uff0c\u6211\u4eec\u7ee7\u7eed\u6765\u8bf4\u8bf4 Python \u4e2d\u5e38\u5e38\u4f1a\u7528\u5230\u7684\u8bed\u53e5\u3002 with with \u8bed\u53e5\u53ef\u4ee5\u8bf4\u662f Python \u4e2d \u201c\u4eba\u751f\u82e6\u77ed\uff0c\u6211\u7528 Python\u201d \u7684\u4ee3\u8868\u4e4b\u4e00\uff0c\u5b83\u53ef\u4ee5\u4f7f\u5f97\u6211\u4eec\u5728\u7f16\u5199\u4ee3\u7801\u7684\u65f6\u5019\u975e\u5e38\u7b80\u77ed\uff0c\u4e14\u884c\u4e4b\u6709\u6548\u3002 \u4e3e\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0cok\uff0c\u4ee5\u4e0a\u5c31\u662f\u6211\u8981&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[18],"tags":[46,47,19,20,45],"_links":{"self":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/525"}],"collection":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=525"}],"version-history":[{"count":3,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/525\/revisions"}],"predecessor-version":[{"id":5874,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/525\/revisions\/5874"}],"wp:attachment":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=525"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=525"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}