{"id":1122585,"date":"2025-01-08T19:22:25","date_gmt":"2025-01-08T11:22:25","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1122585.html"},"modified":"2025-01-08T19:22:28","modified_gmt":"2025-01-08T11:22:28","slug":"python%e9%87%8ctry%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3%e8%af%ad%e6%b3%95%e9%94%99%e8%af%af","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1122585.html","title":{"rendered":"python\u91cctry\u5982\u4f55\u89e3\u51b3\u8bed\u6cd5\u9519\u8bef"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25084401\/1e5a0008-e3f0-47a6-81ff-1d9e75189fe2.webp\" alt=\"python\u91cctry\u5982\u4f55\u89e3\u51b3\u8bed\u6cd5\u9519\u8bef\" \/><\/p>\n<p><p> <strong>Python\u7684<code>try<\/code>\u8bed\u53e5\u4e0d\u80fd\u89e3\u51b3\u8bed\u6cd5\u9519\u8bef\u3001<code>try<\/code>\u8bed\u53e5\u7528\u4e8e\u6355\u83b7\u548c\u5904\u7406\u8fd0\u884c\u65f6\u9519\u8bef\u3001\u8bed\u6cd5\u9519\u8bef\u5728\u4ee3\u7801\u6267\u884c\u524d\u7531\u89e3\u91ca\u5668\u68c0\u6d4b\u5230<\/strong><\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u8bed\u6cd5\u9519\u8bef\u4f1a\u5728\u4ee3\u7801\u88ab\u89e3\u91ca\u5668\u89e3\u6790\u65f6\u88ab\u53d1\u73b0\uff0c\u800c\u4e0d\u662f\u5728\u8fd0\u884c\u65f6\u3002<code>try<\/code>\u8bed\u53e5\u53ea\u80fd\u6355\u83b7\u548c\u5904\u7406\u5728\u4ee3\u7801\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u51fa\u73b0\u7684\u5f02\u5e38\u3002\u56e0\u6b64\uff0c<code>try<\/code>\u8bed\u53e5\u65e0\u6cd5\u89e3\u51b3\u8bed\u6cd5\u9519\u8bef\u3002\u8981\u89e3\u51b3\u8bed\u6cd5\u9519\u8bef\uff0c\u60a8\u9700\u8981\u5728\u7f16\u5199\u4ee3\u7801\u65f6\u8fdb\u884c\u8c03\u8bd5\u548c\u4fee\u6b63\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u5c06\u8be6\u7ec6\u89e3\u91ca\u8fd9\u4e2a\u89c2\u70b9\uff0c\u5e76\u63d0\u4f9b\u4e00\u4e9b\u5b9e\u7528\u7684\u5efa\u8bae\u548c\u65b9\u6cd5\u6765\u5904\u7406Python\u4ee3\u7801\u4e2d\u7684\u9519\u8bef\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u7406\u89e3Python\u4e2d\u7684\u9519\u8bef\u7c7b\u578b<\/h3>\n<\/p>\n<p><p>\u5728\u7f16\u5199Python\u4ee3\u7801\u65f6\uff0c\u901a\u5e38\u4f1a\u9047\u5230\u4e24\u79cd\u4e3b\u8981\u7c7b\u578b\u7684\u9519\u8bef\uff1a\u8bed\u6cd5\u9519\u8bef\u548c\u8fd0\u884c\u65f6\u9519\u8bef\u3002\u4e86\u89e3\u8fd9\u4e24\u8005\u7684\u533a\u522b\u5bf9\u4e8e\u7f16\u5199\u5065\u58ee\u7684\u4ee3\u7801\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<\/p>\n<p><h4>1.1\u3001\u8bed\u6cd5\u9519\u8bef<\/h4>\n<\/p>\n<p><p>\u8bed\u6cd5\u9519\u8bef\uff0c\u4e5f\u79f0\u4e3a\u89e3\u6790\u9519\u8bef\uff0c\u662f\u7531\u4e8e\u4ee3\u7801\u4e0d\u7b26\u5408Python\u7684\u8bed\u6cd5\u89c4\u5219\u800c\u5bfc\u81f4\u7684\u3002\u8fd9\u4e9b\u9519\u8bef\u5728\u4ee3\u7801\u88ab\u89e3\u91ca\u5668\u89e3\u6790\u65f6\u5c31\u4f1a\u88ab\u68c0\u6d4b\u5230\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(&quot;Hello World&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0a\u8ff0\u4ee3\u7801\u4f1a\u5bfc\u81f4\u8bed\u6cd5\u9519\u8bef\uff0c\u56e0\u4e3a\u7f3a\u5c11\u4e86\u4e00\u4e2a\u53f3\u62ec\u53f7\u3002\u8bed\u6cd5\u9519\u8bef\u5fc5\u987b\u5728\u4ee3\u7801\u6267\u884c\u524d\u4fee\u590d\u3002<\/p>\n<\/p>\n<p><h4>1.2\u3001\u8fd0\u884c\u65f6\u9519\u8bef<\/h4>\n<\/p>\n<p><p>\u8fd0\u884c\u65f6\u9519\u8bef\u662f\u5728\u4ee3\u7801\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u53d1\u751f\u7684\u9519\u8bef\uff0c\u8fd9\u4e9b\u9519\u8bef\u53ef\u80fd\u662f\u7531\u4e8e\u5404\u79cd\u539f\u56e0\u5f15\u8d77\u7684\uff0c\u4f8b\u5982\uff1a\u6587\u4ef6\u672a\u627e\u5230\u3001\u9664\u4ee5\u96f6\u3001\u8bbf\u95ee\u4e0d\u5b58\u5728\u7684\u53d8\u91cf\u7b49\u3002\u8fd9\u4e9b\u9519\u8bef\u53ef\u4ee5\u4f7f\u7528<code>try-except<\/code>\u7ed3\u6784\u6765\u6355\u83b7\u548c\u5904\u7406\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">try:<\/p>\n<p>    result = 10 \/ 0<\/p>\n<p>except ZeroDivisionError:<\/p>\n<p>    print(&quot;\u9664\u6570\u4e0d\u80fd\u4e3a\u96f6&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u5982\u4f55\u4f7f\u7528<code>try<\/code>\u8bed\u53e5\u5904\u7406\u8fd0\u884c\u65f6\u9519\u8bef<\/h3>\n<\/p>\n<p><p>\u867d\u7136<code>try<\/code>\u8bed\u53e5\u65e0\u6cd5\u89e3\u51b3\u8bed\u6cd5\u9519\u8bef\uff0c\u4f46\u5b83\u5728\u5904\u7406\u8fd0\u884c\u65f6\u9519\u8bef\u65f6\u975e\u5e38\u6709\u7528\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5b9e\u9645\u5e94\u7528\u573a\u666f\u548c\u793a\u4f8b\u3002<\/p>\n<\/p>\n<p><h4>2.1\u3001\u5904\u7406\u6587\u4ef6\u64cd\u4f5c\u4e2d\u7684\u9519\u8bef<\/h4>\n<\/p>\n<p><p>\u6587\u4ef6\u64cd\u4f5c\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u8fd0\u884c\u65f6\u9519\u8bef\u6765\u6e90\uff0c\u4f8b\u5982\u6587\u4ef6\u4e0d\u5b58\u5728\u6216\u6743\u9650\u4e0d\u8db3\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>try-except<\/code>\u6765\u5904\u7406\u8fd9\u4e9b\u9519\u8bef\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">try:<\/p>\n<p>    with open(&#39;example.txt&#39;, &#39;r&#39;) as file:<\/p>\n<p>        content = file.read()<\/p>\n<p>except FileNotFoundError:<\/p>\n<p>    print(&quot;\u6587\u4ef6\u672a\u627e\u5230&quot;)<\/p>\n<p>except PermissionError:<\/p>\n<p>    print(&quot;\u6ca1\u6709\u6743\u9650\u8bfb\u53d6\u6587\u4ef6&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2.2\u3001\u5904\u7406\u7f51\u7edc\u8bf7\u6c42\u4e2d\u7684\u9519\u8bef<\/h4>\n<\/p>\n<p><p>\u5728\u8fdb\u884c\u7f51\u7edc\u8bf7\u6c42\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u5404\u79cd\u9519\u8bef\uff0c\u4f8b\u5982\u8fde\u63a5\u8d85\u65f6\u6216\u65e0\u6cd5\u89e3\u6790\u57df\u540d\u3002\u53ef\u4ee5\u4f7f\u7528<code>try-except<\/code>\u6765\u6355\u83b7\u8fd9\u4e9b\u9519\u8bef\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>try:<\/p>\n<p>    response = requests.get(&#39;http:\/\/example.com&#39;)<\/p>\n<p>    response.r<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>se_for_status()<\/p>\n<p>except requests.exceptions.HTTPError as err:<\/p>\n<p>    print(f&quot;HTTP\u9519\u8bef\u53d1\u751f: {err}&quot;)<\/p>\n<p>except requests.exceptions.ConnectionError:<\/p>\n<p>    print(&quot;\u8fde\u63a5\u9519\u8bef&quot;)<\/p>\n<p>except requests.exceptions.Timeout:<\/p>\n<p>    print(&quot;\u8bf7\u6c42\u8d85\u65f6&quot;)<\/p>\n<p>except requests.exceptions.RequestException as err:<\/p>\n<p>    print(f&quot;\u8bf7\u6c42\u53d1\u751f\u9519\u8bef: {err}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u8c03\u8bd5\u548c\u4fee\u590d\u8bed\u6cd5\u9519\u8bef\u7684\u65b9\u6cd5<\/h3>\n<\/p>\n<p><p>\u65e2\u7136<code>try<\/code>\u8bed\u53e5\u4e0d\u80fd\u89e3\u51b3\u8bed\u6cd5\u9519\u8bef\uff0c\u6211\u4eec\u9700\u8981\u5176\u4ed6\u65b9\u6cd5\u6765\u8c03\u8bd5\u548c\u4fee\u590d\u8fd9\u4e9b\u9519\u8bef\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5b9e\u7528\u7684\u5efa\u8bae\u3002<\/p>\n<\/p>\n<p><h4>3.1\u3001\u4f7f\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528\u529f\u80fd\u5f3a\u5927\u7684IDE\uff0c\u5982PyCharm\u3001Visual Studio Code\u7b49\uff0c\u5b83\u4eec\u53ef\u4ee5\u5728\u7f16\u5199\u4ee3\u7801\u65f6\u5b9e\u65f6\u68c0\u6d4b\u8bed\u6cd5\u9519\u8bef\uff0c\u5e76\u63d0\u4f9b\u8be6\u7ec6\u7684\u9519\u8bef\u4fe1\u606f\u548c\u4fee\u590d\u5efa\u8bae\u3002<\/p>\n<\/p>\n<p><h4>3.2\u3001\u9010\u884c\u68c0\u67e5\u4ee3\u7801<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u6ca1\u6709\u4f7f\u7528IDE\uff0c\u53ef\u4ee5\u9010\u884c\u68c0\u67e5\u4ee3\u7801\uff0c\u786e\u4fdd\u6bcf\u4e00\u884c\u90fd\u7b26\u5408Python\u7684\u8bed\u6cd5\u89c4\u5219\u3002\u4f8b\u5982\uff0c\u68c0\u67e5\u62ec\u53f7\u662f\u5426\u5339\u914d\uff0c\u7f29\u8fdb\u662f\u5426\u6b63\u786e\uff0c\u5173\u952e\u8bcd\u662f\u5426\u62fc\u5199\u6b63\u786e\u7b49\u3002<\/p>\n<\/p>\n<p><h4>3.3\u3001\u5229\u7528Lint\u5de5\u5177<\/h4>\n<\/p>\n<p><p>Lint\u5de5\u5177\u5982Pylint\u3001Flake8\u7b49\u53ef\u4ee5\u9759\u6001\u5206\u6790\u4ee3\u7801\uff0c\u68c0\u6d4b\u8bed\u6cd5\u9519\u8bef\u548c\u6f5c\u5728\u95ee\u9898\u3002\u5b83\u4eec\u53ef\u4ee5\u96c6\u6210\u5230<a href=\"https:\/\/docs.pingcode.com\/blog\/devops\/52691.html\" target=\"_blank\">CI\/CD<\/a>\u7ba1\u9053\u4e2d\uff0c\u81ea\u52a8\u68c0\u67e5\u4ee3\u7801\u8d28\u91cf\u3002<\/p>\n<\/p>\n<p><h4>3.4\u3001\u53c2\u8003\u5b98\u65b9\u6587\u6863\u548c\u793e\u533a\u8d44\u6e90<\/h4>\n<\/p>\n<p><p>Python\u5b98\u65b9\u6587\u6863\u548c\u793e\u533a\u8d44\u6e90\u63d0\u4f9b\u4e86\u5927\u91cf\u7684\u793a\u4f8b\u548c\u6700\u4f73\u5b9e\u8df5\uff0c\u53ef\u4ee5\u5e2e\u52a9\u60a8\u7406\u89e3\u548c\u9075\u5faaPython\u7684\u8bed\u6cd5\u89c4\u5219\u3002\u9047\u5230\u95ee\u9898\u65f6\uff0c\u53ef\u4ee5\u641c\u7d22\u76f8\u5173\u6587\u6863\u6216\u5728\u793e\u533a\u8bba\u575b\u63d0\u51fa\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u7f16\u5199\u5065\u58ee\u4ee3\u7801\u7684\u6700\u4f73\u5b9e\u8df5<\/h3>\n<\/p>\n<p><p>\u4e3a\u4e86\u7f16\u5199\u5065\u58ee\u4e14\u6613\u4e8e\u7ef4\u62a4\u7684\u4ee3\u7801\uff0c\u9664\u4e86\u5904\u7406\u8fd0\u884c\u65f6\u9519\u8bef\u548c\u4fee\u590d\u8bed\u6cd5\u9519\u8bef\u5916\uff0c\u8fd8\u5e94\u9075\u5faa\u4e00\u4e9b\u6700\u4f73\u5b9e\u8df5\u3002<\/p>\n<\/p>\n<p><h4>4.1\u3001\u7f16\u5199\u5355\u5143\u6d4b\u8bd5<\/h4>\n<\/p>\n<p><p>\u5355\u5143\u6d4b\u8bd5\u53ef\u4ee5\u5e2e\u52a9\u60a8\u5728\u4ee3\u7801\u66f4\u6539\u540e\u5feb\u901f\u68c0\u6d4b\u9519\u8bef\u3002\u4f7f\u7528unittest\u3001pytest\u7b49\u6d4b\u8bd5\u6846\u67b6\u7f16\u5199\u6d4b\u8bd5\u7528\u4f8b\uff0c\u8986\u76d6\u4ee3\u7801\u7684\u5404\u4e2a\u65b9\u9762\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import unittest<\/p>\n<p>def add(a, b):<\/p>\n<p>    return a + b<\/p>\n<p>class TestMath(unittest.TestCase):<\/p>\n<p>    def test_add(self):<\/p>\n<p>        self.assertEqual(add(1, 2), 3)<\/p>\n<p>if __name__ == &#39;__main__&#39;:<\/p>\n<p>    unittest.main()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4.2\u3001\u9075\u5faa\u7f16\u7801\u89c4\u8303<\/h4>\n<\/p>\n<p><p>\u9075\u5faa\u7f16\u7801\u89c4\u8303\uff0c\u5982PEP 8\uff0c\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002\u4f7f\u7528\u4ee3\u7801\u683c\u5f0f\u5316\u5de5\u5177\uff0c\u5982black\uff0c\u53ef\u4ee5\u81ea\u52a8\u683c\u5f0f\u5316\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><h4>4.3\u3001\u8bb0\u5f55\u8be6\u7ec6\u7684\u9519\u8bef\u65e5\u5fd7<\/h4>\n<\/p>\n<p><p>\u8bb0\u5f55\u8be6\u7ec6\u7684\u9519\u8bef\u65e5\u5fd7\u53ef\u4ee5\u5e2e\u52a9\u60a8\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u5feb\u901f\u5b9a\u4f4d\u548c\u4fee\u590d\u9519\u8bef\u3002\u4f7f\u7528logging\u6a21\u5757\u8bb0\u5f55\u9519\u8bef\u4fe1\u606f\u548c\u5806\u6808\u8ddf\u8e2a\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import logging<\/p>\n<p>logging.basicConfig(filename=&#39;app.log&#39;, level=logging.ERROR)<\/p>\n<p>try:<\/p>\n<p>    1 \/ 0<\/p>\n<p>except ZeroDivisionError as e:<\/p>\n<p>    logging.error(&quot;\u9664\u6570\u4e0d\u80fd\u4e3a\u96f6&quot;, exc_info=True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p><strong>Python\u7684<code>try<\/code>\u8bed\u53e5\u4e0d\u80fd\u89e3\u51b3\u8bed\u6cd5\u9519\u8bef\u3001<code>try<\/code>\u8bed\u53e5\u7528\u4e8e\u6355\u83b7\u548c\u5904\u7406\u8fd0\u884c\u65f6\u9519\u8bef\u3001\u8bed\u6cd5\u9519\u8bef\u5728\u4ee3\u7801\u6267\u884c\u524d\u7531\u89e3\u91ca\u5668\u68c0\u6d4b\u5230<\/strong>\u3002\u8981\u7f16\u5199\u5065\u58ee\u4e14\u9ad8\u6548\u7684Python\u4ee3\u7801\uff0c\u9700\u8981\u7406\u89e3\u8fd9\u4e24\u79cd\u9519\u8bef\u7c7b\u578b\uff0c\u5e76\u4f7f\u7528\u9002\u5f53\u7684\u65b9\u6cd5\u6765\u5904\u7406\u5b83\u4eec\u3002\u901a\u8fc7\u4f7f\u7528IDE\u3001Lint\u5de5\u5177\u3001\u7f16\u5199\u5355\u5143\u6d4b\u8bd5\u3001\u9075\u5faa\u7f16\u7801\u89c4\u8303\u548c\u8bb0\u5f55\u9519\u8bef\u65e5\u5fd7\uff0c\u53ef\u4ee5\u5927\u5927\u63d0\u9ad8\u4ee3\u7801\u7684\u8d28\u91cf\u548c\u53ef\u7ef4\u62a4\u6027\u3002\u5e0c\u671b\u8fd9\u4e9b\u5efa\u8bae\u548c\u793a\u4f8b\u80fd\u5e2e\u52a9\u60a8\u5728Python\u7f16\u7a0b\u4e2d\u66f4\u52a0\u5f97\u5fc3\u5e94\u624b\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5728Python\u4e2d\uff0ctry\u5757\u53ef\u4ee5\u6355\u83b7\u54ea\u4e9b\u7c7b\u578b\u7684\u9519\u8bef\uff1f<\/strong><br \/>try\u5757\u4e3b\u8981\u7528\u4e8e\u6355\u83b7\u8fd0\u884c\u65f6\u9519\u8bef\uff08\u5982TypeError\u3001ValueError\u7b49\uff09\uff0c\u4f46\u4e0d\u9002\u7528\u4e8e\u8bed\u6cd5\u9519\u8bef\u3002\u8bed\u6cd5\u9519\u8bef\u5728\u4ee3\u7801\u6267\u884c\u4e4b\u524d\u5c31\u4f1a\u88ab\u89e3\u91ca\u5668\u68c0\u6d4b\u5230\uff0c\u56e0\u6b64try\u5757\u65e0\u6cd5\u5904\u7406\u8fd9\u4e9b\u9519\u8bef\u3002\u5982\u679c\u9700\u8981\u5904\u7406\u8bed\u6cd5\u9519\u8bef\uff0c\u5efa\u8bae\u5728\u7f16\u5199\u4ee3\u7801\u65f6\u4f7f\u7528\u4ee3\u7801\u7f16\u8f91\u5668\u6216IDE\u7684\u8bed\u6cd5\u68c0\u67e5\u529f\u80fd\uff0c\u4ee5\u4fbf\u63d0\u524d\u53d1\u73b0\u95ee\u9898\u3002<\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528try\u5757\u6765\u5904\u7406\u8fd0\u884c\u65f6\u9519\u8bef\uff1f<\/strong><br \/>\u4f7f\u7528try\u5757\u53ef\u4ee5\u6709\u6548\u5730\u6355\u83b7\u8fd0\u884c\u65f6\u9519\u8bef\uff0c\u9632\u6b62\u7a0b\u5e8f\u5d29\u6e83\u3002\u5177\u4f53\u65b9\u6cd5\u662f\u5728try\u5757\u4e2d\u653e\u7f6e\u53ef\u80fd\u53d1\u751f\u9519\u8bef\u7684\u4ee3\u7801\uff0c\u5e76\u4f7f\u7528except\u5757\u6765\u6307\u5b9a\u9519\u8bef\u7c7b\u578b\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u8fd9\u6837\u7f16\u5199\u4ee3\u7801\uff1a  <\/p>\n<pre><code class=\"language-python\">try:\n    result = 10 \/ 0  # \u53ef\u80fd\u5f15\u53d1ZeroDivisionError\nexcept ZeroDivisionError:\n    print(&quot;\u4e0d\u80fd\u9664\u4ee5\u96f6\uff01&quot;)\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u80fd\u591f\u8ba9\u7a0b\u5e8f\u5728\u9047\u5230\u9519\u8bef\u65f6\u7ee7\u7eed\u8fd0\u884c\uff0c\u63d0\u4f9b\u7528\u6237\u53cb\u597d\u7684\u9519\u8bef\u63d0\u793a\u3002<\/p>\n<p><strong>\u5982\u4f55\u8c03\u8bd5Python\u4ee3\u7801\u4e2d\u7684\u8bed\u6cd5\u9519\u8bef\uff1f<\/strong><br \/>\u8c03\u8bd5\u8bed\u6cd5\u9519\u8bef\u901a\u5e38\u9700\u8981\u4ed4\u7ec6\u68c0\u67e5\u4ee3\u7801\u7684\u7ed3\u6784\u548c\u8bed\u6cd5\u3002\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884c\u4ee3\u7801\u65f6\u7684\u9519\u8bef\u6d88\u606f\u6765\u5b9a\u4f4d\u95ee\u9898\u7684\u884c\u53f7\u3002\u5e38\u89c1\u7684\u8bed\u6cd5\u9519\u8bef\u5305\u62ec\u7f3a\u5931\u62ec\u53f7\u3001\u62fc\u5199\u9519\u8bef\u548c\u9519\u8bef\u7684\u7f29\u8fdb\u7b49\u3002\u6b64\u5916\uff0c\u4f7f\u7528\u4ee3\u7801\u7f16\u8f91\u5668\u7684\u81ea\u52a8\u8865\u5168\u548c\u4ee3\u7801\u9ad8\u4eae\u529f\u80fd\uff0c\u53ef\u4ee5\u5e2e\u52a9\u8bc6\u522b\u6f5c\u5728\u7684\u8bed\u6cd5\u9519\u8bef\uff0c\u786e\u4fdd\u4ee3\u7801\u7684\u6b63\u786e\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u7684try\u8bed\u53e5\u4e0d\u80fd\u89e3\u51b3\u8bed\u6cd5\u9519\u8bef\u3001try\u8bed\u53e5\u7528\u4e8e\u6355\u83b7\u548c\u5904\u7406\u8fd0\u884c\u65f6\u9519\u8bef\u3001\u8bed\u6cd5\u9519\u8bef\u5728\u4ee3\u7801\u6267\u884c\u524d\u7531\u89e3\u91ca\u5668\u68c0\u6d4b [&hellip;]","protected":false},"author":3,"featured_media":1122594,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1122585"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1122585"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1122585\/revisions"}],"predecessor-version":[{"id":1122596,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1122585\/revisions\/1122596"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1122594"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1122585"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1122585"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1122585"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}