{"id":307177,"date":"2024-05-20T20:29:03","date_gmt":"2024-05-20T12:29:03","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/307177.html"},"modified":"2024-05-20T20:29:13","modified_gmt":"2024-05-20T12:29:13","slug":"python%ef%bc%9a-if-__name__-__main__-%e5%88%b0%e5%ba%95%e6%98%af%e4%bb%80%e4%b9%88%e9%ac%bc","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/307177.html","title":{"rendered":"python\uff1a if __name__ == \\__main__\\ \u5230\u5e95\u662f\u4ec0\u4e48\u9b3c"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/26223547\/9db27bb1-a237-4c5c-9b82-645add5e7c16.webp\" alt=\"python\uff1a if __name__ == \\__main__\\ \u5230\u5e95\u662f\u4ec0\u4e48\u9b3c\" \/><\/p>\n<p><p>\u5728Python\u7f16\u7a0b\u4e2d\uff0c<code>if __name__ == &quot;__m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n__&quot;<\/code> \u662f\u4e00\u79cd\u5e38\u7528\u7684\u4ee3\u7801\u4e3b\u6a21\u5f0f\u3002<strong>\u5b83\u5224\u65ad\u5f53\u524d\u6587\u4ef6\u662f\u5426\u4f5c\u4e3a\u4e3b\u7a0b\u5e8f\u8fd0\u884c<\/strong>\u3001<strong>\u9632\u6b62\u4ee3\u7801\u88ab\u610f\u5916\u6267\u884c<\/strong>\u3001<strong>\u63d0\u4f9b\u6a21\u5757\u6d4b\u8bd5\u4ee3\u7801\u7684\u6267\u884c\u5165\u53e3<\/strong>\u3002\u5f53Python\u6587\u4ef6\u88ab\u76f4\u63a5\u8fd0\u884c\u65f6\uff0c\u5176\u5185\u7f6e\u7684<code>__name__<\/code>\u53d8\u91cf\u88ab\u8d4b\u503c\u4e3a&quot;<strong>main<\/strong>&quot;\uff1b\u800c\u5f53\u6587\u4ef6\u88ab\u5bfc\u5165\u5230\u5176\u4ed6\u6587\u4ef6\u65f6\uff0c<code>__name__<\/code>\u7684\u503c\u5c06\u53d8\u6210\u8be5\u6587\u4ef6\u7684\u6a21\u5757\u540d\u3002\u8fd9\u4e2a\u529f\u80fd\u8ba9\u5f00\u53d1\u8005\u80fd\u591f\u63a7\u5236\u67d0\u4e9b\u4ee3\u7801\u53ea\u5728\u6587\u4ef6\u4f5c\u4e3a\u4e3b\u7a0b\u5e8f\u8fd0\u884c\u65f6\u624d\u6267\u884c\uff0c\u800c\u5728\u88ab\u5176\u4ed6\u6a21\u5757\u5bfc\u5165\u65f6\u4e0d\u6267\u884c\u3002<\/p>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u6df1\u5165\u6316\u6398\u5e76\u89e3\u91ca<code>if __name__ == &quot;__main__&quot;<\/code>\u7684\u7528\u6cd5\uff0c\u5e76\u63a2\u8ba8\u5b83\u5728\u5b9e\u9645\u7f16\u7a0b\u4e2d\u7684\u91cd\u8981\u6027\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u7406\u89e3<code>if __name__ == &quot;__main__&quot;<\/code>\u7684\u5de5\u4f5c\u539f\u7406<\/h3>\n<\/p>\n<p><p>\u5f53Python\u89e3\u91ca\u5668\u8fd0\u884c\u4e00\u4e2a\u6a21\u5757\uff08\u4e00\u4e2a.py\u6587\u4ef6\uff09\u65f6\uff0c\u5b83\u4f1a\u5c06\u4e00\u4e9b\u7279\u6b8a\u53d8\u91cf\u8d4b\u503c\uff0c\u5176\u4e2d<code>__name__<\/code>\u662f\u6700\u91cd\u8981\u7684\u4e00\u4e2a\u3002\u4e86\u89e3\u8fd9\u4e00\u70b9\uff0c\u6709\u52a9\u4e8e\u6211\u4eec\u7f16\u5199\u65e2\u53ef\u4ee5\u72ec\u7acb\u6267\u884c\u4e5f\u53ef\u4f5c\u4e3a\u6a21\u5757\u88ab\u5bfc\u5165\u7684\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><h4>\u6a21\u5757\u662f\u72ec\u7acb\u8fd0\u884c\u7684<\/h4>\n<\/p>\n<p><p>\u5f53\u6a21\u5757\u4f5c\u4e3a\u4e3b\u7a0b\u5e8f\u8fd0\u884c\u65f6\uff0c<code>__name__<\/code>\u5c06\u88ab\u8bbe\u7f6e\u4e3a\u5b57\u7b26\u4e32<code>&quot;__main__&quot;<\/code>\u3002\u8fd9\u610f\u5473\u7740\u6211\u4eec\u53ef\u4ee5\u68c0\u6d4b\u8fd9\u4e2a\u5c5e\u6027\uff0c\u6765\u51b3\u5b9a\u6267\u884c\u54ea\u4e9b\u4ee3\u7801\u5757\u3002<\/p>\n<\/p>\n<p><p><strong>\u793a\u4f8b<\/strong>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def function_a():<\/p>\n<p>    print(&quot;Function A is called&quot;)<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    function_a()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\u4e2d\uff0c<code>function_a<\/code>\u53ea\u6709\u5728\u8be5\u6a21\u5757\u662f\u4f5c\u4e3a\u4e3b\u7a0b\u5e8f\u8fd0\u884c\u65f6\u624d\u4f1a\u88ab\u8c03\u7528\u3002\u5982\u679c\u6a21\u5757\u88ab\u53e6\u4e00\u4e2a\u6a21\u5757\u5bfc\u5165\uff0c<code>function_a<\/code>\u4e0d\u4f1a\u88ab\u6267\u884c\u3002<\/p>\n<\/p>\n<p><h4>\u6a21\u5757\u88ab\u5bfc\u5165<\/h4>\n<\/p>\n<p><p>\u5f53\u6a21\u5757\u88ab\u5176\u4ed6Python\u6587\u4ef6import\u65f6\uff0c<code>__name__<\/code>\u7684\u503c\u5c06\u4f1a\u53d8\u6210\u6a21\u5757\u7684\u540d\u5b57\u3002\u8fd9\u6837\u6211\u4eec\u53ef\u4ee5\u4f7f\u5f97\u67d0\u4e9b\u4ee3\u7801\u53ea\u5728\u6a21\u5757\u88ab\u5bfc\u5165\u65f6\u6267\u884c\uff0c\u800c\u5176\u4ed6\u4ee3\u7801\u5728\u88ab\u76f4\u63a5\u8fd0\u884c\u65f6\u6267\u884c\u3002<\/p>\n<\/p>\n<p><p><strong>\u793a\u4f8b<\/strong>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def function_b():<\/p>\n<p>    print(&quot;Function B is called&quot;)<\/p>\n<p>def function_c():<\/p>\n<p>    print(&quot;Function C is called&quot;)<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    function_b()<\/p>\n<p>else:<\/p>\n<p>    function_c()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u91cc\uff0c\u5f53\u6a21\u5757\u76f4\u63a5\u8fd0\u884c\u65f6\uff0c\u5c06\u8c03\u7528<code>function_b<\/code>\u3002\u4f46\u5982\u679c\u4ece\u53e6\u4e00\u4e2a\u6a21\u5757\u5bfc\u5165\u8be5\u6a21\u5757\uff0c\u5c06\u4f1a\u8fd0\u884c<code>function_c<\/code>\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528\u6848\u4f8b\u4e0e\u6700\u4f73\u5b9e\u8df5<\/h3>\n<\/p>\n<p><p><code>if __name__ == &quot;__main__&quot;<\/code>\u7684\u4f7f\u7528\u6848\u4f8b\u6781\u4e3a\u5e7f\u6cdb\uff0c\u4ece\u7b80\u5355\u7684\u811a\u672c\u5230\u590d\u6742\u7684\u6a21\u5757\u7cfb\u7edf\uff0c\u5b83\u90fd\u626e\u6f14\u7740\u91cd\u8981\u7684\u89d2\u8272\u3002<\/p>\n<\/p>\n<p><h4>1. \u6d4b\u8bd5\u548c\u8c03\u8bd5<\/h4>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u5728<code>if __name__ == &quot;__main__&quot;<\/code>\u4e4b\u540e\u5b89\u6392\u6a21\u5757\u7684\u6d4b\u8bd5\u4ee3\u7801\u3002\u8fd9\u6837\uff0c\u8fd9\u4e9b\u6d4b\u8bd5\u53ea\u6709\u5728\u8be5\u6587\u4ef6\u4f5c\u4e3a\u4e3b\u7a0b\u5e8f\u8fd0\u884c\u65f6\u624d\u4f1a\u88ab\u6267\u884c\uff0c\u800c\u4e0d\u4f1a\u5f71\u54cd\u5176\u4ed6\u5bfc\u5165\u8be5\u6a21\u5757\u7684\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<p><p><strong>\u793a\u4f8b<\/strong>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># math_functions.py<\/p>\n<p>def add(a, b):<\/p>\n<p>    return a + b<\/p>\n<p>def test_add():<\/p>\n<p>    assert add(2, 3) == 5<\/p>\n<p>    print(&quot;Test for add passed.&quot;)<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    test_add()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u5176\u4ed6\u6587\u4ef6\u6267\u884c\u4e86<code>import math_functions<\/code>\uff0c\u90a3\u4e48<code>test_add<\/code>\u51fd\u6570\u4e0d\u4f1a\u88ab\u6267\u884c\u3002\u4f46\u5f53\u4f60\u76f4\u63a5\u8fd0\u884c<code>math_functions.py<\/code>\u65f6\uff0c\u4f60\u5c06\u770b\u5230\u6d4b\u8bd5\u901a\u8fc7\u7684\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><h4>2. \u811a\u672c\u81f3\u6a21\u5757\u7684\u8f6c\u53d8<\/h4>\n<\/p>\n<p><p>\u5f53\u4f60\u7684\u811a\u672c\u53d1\u5c55\u4e3a\u590d\u6742\u7684\u5e94\u7528\u65f6\uff0c\u53ef\u80fd\u9700\u8981\u5c06\u67d0\u4e9b\u529f\u80fd\u72ec\u7acb\u4e3a\u6a21\u5757\u3002\u5229\u7528<code>if __name__ == &quot;__main__&quot;<\/code>\u53ef\u4ee5\u65e0\u7f1d\u8fc7\u6e21\uff0c\u65e0\u9700\u66f4\u6539\u4ee3\u7801\u7684\u4e3b\u4f53\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># my_script.py<\/p>\n<p>def main():<\/p>\n<p>    # \u4e3b\u7a0b\u5e8f\u903b\u8f91<\/p>\n<p>    print(&quot;This is the main routine.&quot;)<\/p>\n<h2><strong>\u5176\u4ed6\u529f\u80fd\u51fd\u6570<\/strong><\/h2>\n<h2><strong>...<\/strong><\/h2>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    main()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5176\u4e2d\uff0c<code>main()<\/code>\u51fd\u6570\u4ee3\u8868\u539f\u6765\u811a\u672c\u7684\u4e3b\u8981\u5185\u5bb9\uff0c\u73b0\u5728\u5b83\u53ef\u4ee5\u88ab\u5f53\u4f5c\u6a21\u5757\u5bfc\u5165\uff0c\u800c\u4e0d\u6267\u884c<code>main()<\/code>\u51fd\u6570\u4e2d\u7684\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u7ed3\u5408\u5b9e\u4f8b\u7406\u89e3\u6a21\u5757\u5316\u7f16\u7a0b<\/h3>\n<\/p>\n<p><p>\u5b9e\u73b0\u6a21\u5757\u5316\u53ef\u4ee5\u4f7f\u4ee3\u7801\u66f4\u52a0\u6574\u6d01\u3001\u6613\u4e8e\u7ba1\u7406\u548c\u6269\u5c55\u3002<code>if __name__ == &quot;__main__&quot;<\/code>\u662f\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u7684\u5173\u952e\u5de5\u5177\u3002<\/p>\n<\/p>\n<p><h4>\u5b8c\u6574\u7684\u5e94\u7528\u6848\u4f8b<\/h4>\n<\/p>\n<p><p>\u8003\u8651\u4e00\u4e2a\u66f4\u5b9e\u9645\u7684\u4f8b\u5b50\uff0c\u6211\u4eec\u6709\u51e0\u4e2a\u6a21\u5757\u7ec4\u6210\u7684\u5e94\u7528\uff0c\u5982\uff1a<code>main.py<\/code>\u3001<code>database.py<\/code>\u3001<code>utils.py<\/code>\u3002\u6bcf\u4e2a\u6a21\u5757\u90fd\u6709\u5404\u81ea\u7684\u529f\u80fd\uff0c\u800c<code>main.py<\/code>\u5219\u662f\u5165\u53e3\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># main.py<\/p>\n<p>import database<\/p>\n<p>import utils<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    # \u5e94\u7528\u542f\u52a8\u903b\u8f91<\/p>\n<p>    database.setup()<\/p>\n<p>    utils.perform_initialization()<\/p>\n<p>    print(&quot;Application is running.&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u91cc\uff0c\u65e0\u8bba\u662f<code>database.py<\/code>\u8fd8\u662f<code>utils.py<\/code>\uff0c\u53ef\u80fd\u5b83\u4eec\u5404\u81ea\u90fd\u6709<code>if __name__ == &quot;__main__&quot;<\/code>\u90e8\u5206\u6765\u8fdb\u884c\u81ea\u6211\u6d4b\u8bd5\u6216\u9644\u5e26\u7684\u5355\u72ec\u529f\u80fd\u3002\u4f46\u662f\uff0c\u5f53\u901a\u8fc7<code>main.py<\/code>\u542f\u52a8\u5e94\u7528\u65f6\uff0c\u5b83\u4eec\u7684\u8fd9\u90e8\u5206\u4ee3\u7801\u5c31\u4e0d\u4f1a\u6267\u884c\u3002<\/p>\n<\/p>\n<p><h4>3. \u5b9e\u73b0\u53ef\u590d\u7528\u7684\u6a21\u5757<\/h4>\n<\/p>\n<p><p>\u501f\u52a9<code>if __name__ == &quot;__main__&quot;<\/code>\u7684\u6a21\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u65e2\u53ef\u4ee5\u5728\u5176\u4ed6\u5730\u65b9\u91cd\u590d\u4f7f\u7528\uff0c\u4e5f\u53ef\u4ee5\u5355\u72ec\u6267\u884c\u7684\u6a21\u5757\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># reusable_module.py<\/p>\n<p>def perform_action():<\/p>\n<p>    print(&quot;Action is performed.&quot;)<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    # \u68c0\u67e5\u6a21\u5757\u6027\u80fd\u3001\u6f14\u793a\u529f\u80fd\u7b49<\/p>\n<p>    perform_action()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u7ed3\u8bba<\/h3>\n<\/p>\n<p><p><code>if __name__ == &quot;__main__&quot;<\/code>\u5728Python\u4e2d\u7684\u8fd0\u7528\u662f\u975e\u5e38\u5e7f\u6cdb\u4e14\u6709\u7528\u7684\uff0c\u5b83\u5e2e\u52a9\u5f00\u53d1\u8005\u533a\u5206\u6a21\u5757\u76f4\u63a5\u8fd0\u884c\u4e0e\u88ab\u5bfc\u5165\u65f6\u7684\u884c\u4e3a\uff0c\u4fdd\u8bc1\u4e86\u4ee3\u7801\u7684\u53ef\u590d\u7528\u6027\u548c\u6a21\u5757\u5316\uff0c\u540c\u65f6\u4e5f\u4f7f\u5f97\u6d4b\u8bd5\u548c\u8c03\u8bd5\u5de5\u4f5c\u66f4\u4e3a\u7b80\u6d01\u76f4\u63a5\u3002<\/p>\n<\/p>\n<p><p>\u6700\u7ec8\uff0c<code>if __name__ == &quot;__main__&quot;<\/code>\u5141\u8bb8\u6211\u4eec\u4ee5\u66f4\u4f18\u96c5\u3001\u66f4\u6a21\u5757\u5316\u7684\u65b9\u5f0f\u5199\u51fa\u66f4\u52a0\u5f3a\u5927\u548c\u7ec4\u7ec7\u826f\u597d\u7684Python\u4ee3\u7801\uff0c\u5b83\u662f\u6bcf\u4e2aPython\u5f00\u53d1\u8005\u5de5\u5177\u7bb1\u4e2d\u4e0d\u53ef\u6216\u7f3a\u7684\u4e00\u90e8\u5206\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<ol>\n<li>\n<p><strong>\u4e3a\u4ec0\u4e48\u5728Python\u4e2d\u8981\u4f7f\u7528if <strong>name<\/strong> == &quot;<strong>main<\/strong>&quot;\u5462\uff1f<\/strong><br \/>\n\u5728Python\u4e2d\uff0cif <strong>name<\/strong> == &quot;<strong>main<\/strong>&quot;\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u7528\u6cd5\u3002\u5b83\u7684\u4f5c\u7528\u662f\u5224\u65ad\u5f53\u524d\u6a21\u5757\u662f\u5426\u88ab\u76f4\u63a5\u8fd0\u884c\uff0c\u800c\u4e0d\u662f\u4f5c\u4e3a\u4e00\u4e2a\u5bfc\u5165\u6a21\u5757\u3002\u8fd9\u4e2a\u5224\u65ad\u8bed\u53e5\u7ecf\u5e38\u88ab\u7528\u6765\u5728\u4ee3\u7801\u4e2d\u6dfb\u52a0\u4e00\u4e9b\u4ec5\u5728\u6a21\u5757\u76f4\u63a5\u8fd0\u884c\u65f6\u6267\u884c\u7684\u4ee3\u7801\u5757\uff0c\u800c\u4e0d\u4f1a\u5728\u6a21\u5757\u4f5c\u4e3a\u5bfc\u5165\u6a21\u5757\u65f6\u6267\u884c\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u5982\u4f55\u7406\u89e3if <strong>name<\/strong> == &quot;<strong>main<\/strong>&quot;\u7684\u5de5\u4f5c\u539f\u7406\uff1f<\/strong><br \/>\n\u5f53Python\u89e3\u91ca\u5668\u8fd0\u884c\u4e00\u4e2a\u811a\u672c\u65f6\uff0c\u5b83\u4f1a\u4e3a\u8be5\u811a\u672c\u521b\u5efa\u4e00\u4e2a\u5185\u7f6e\u53d8\u91cf__name__\uff0c\u5e76\u5c06\u5176\u6307\u5b9a\u4e3a&quot;<strong>main<\/strong>&quot;\u3002\u56e0\u6b64\uff0c\u5f53\u811a\u672c\u76f4\u63a5\u88ab\u8fd0\u884c\u65f6\uff0cif <strong>name<\/strong> == &quot;<strong>main<\/strong>&quot;\u7684\u6761\u4ef6\u4e3a\u771f\uff0c\u5c31\u4f1a\u6267\u884c\u5176\u540e\u7684\u4ee3\u7801\u5757\u3002\u76f8\u53cd\uff0c\u5982\u679c\u8be5\u811a\u672c\u88ab\u4f5c\u4e3a\u4e00\u4e2a\u5bfc\u5165\u6a21\u5757\uff0c\u90a3\u4e48__name__\u7684\u503c\u5c06\u4f1a\u662f\u8be5\u6a21\u5757\u7684\u540d\u79f0\uff0c\u800c\u4e0d\u662f&quot;<strong>main<\/strong>&quot;\uff0c\u6761\u4ef6\u4e3a\u5047\uff0c\u540e\u7eed\u4ee3\u7801\u5757\u5c06\u4e0d\u4f1a\u6267\u884c\u3002<\/p>\n<\/li>\n<li>\n<p><strong>if <strong>name<\/strong> == &quot;<strong>main<\/strong>&quot;\u7684\u5176\u4ed6\u7528\u9014\u6709\u54ea\u4e9b\uff1f<\/strong><br \/>\n\u9664\u4e86\u7528\u6765\u5224\u65ad\u6a21\u5757\u662f\u5426\u88ab\u76f4\u63a5\u8fd0\u884c\uff0cif <strong>name<\/strong> == &quot;<strong>main<\/strong>&quot;\u8fd8\u53ef\u4ee5\u4f5c\u4e3a\u4e00\u4e2a\u5165\u53e3\u70b9\uff0c\u5728\u4e3b\u7a0b\u5e8f\u4e2d\u6267\u884c\u4e00\u4e9b\u521d\u59cb\u5316\u5de5\u4f5c\u548c\u51fd\u6570\u8c03\u7528\uff0c\u4ee5\u53ca\u8bbe\u7f6e\u4e00\u4e9b\u5168\u5c40\u914d\u7f6e\u7b49\u3002\u8fd9\u79cd\u7528\u6cd5\u5728\u5f00\u53d1\u5927\u578b\u9879\u76ee\u65f6\u5341\u5206\u6709\u7528\uff0c\u53ef\u4ee5\u4fdd\u6301\u4ee3\u7801\u7684\u6574\u6d01\u6027\u548c\u6a21\u5757\u95f4\u7684\u72ec\u7acb\u6027\u3002\u4f7f\u7528\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u4f7f\u5f97\u6a21\u5757\u5177\u6709\u53ef\u590d\u7528\u6027\uff0c\u5e76\u4e14\u53ef\u4ee5\u5728\u4e0d\u540c\u7684\u4e0a\u4e0b\u6587\u4e2d\u6267\u884c\u4e0d\u540c\u7684\u64cd\u4f5c\u3002<\/p>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u7f16\u7a0b\u4e2d\uff0cif __name__ == &quot;__mAIn__&quot; \u662f\u4e00\u79cd\u5e38\u7528\u7684\u4ee3\u7801 [&hellip;]","protected":false},"author":3,"featured_media":307187,"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\/307177"}],"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=307177"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/307177\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/307187"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=307177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=307177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=307177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}