{"id":957161,"date":"2024-12-27T02:53:12","date_gmt":"2024-12-26T18:53:12","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/957161.html"},"modified":"2024-12-27T02:53:15","modified_gmt":"2024-12-26T18:53:15","slug":"python%e5%a6%82%e4%bd%95%e6%9f%a5%e7%9c%8b%e5%91%bd%e5%90%8d%e7%a9%ba%e9%97%b4","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/957161.html","title":{"rendered":"python\u5982\u4f55\u67e5\u770b\u547d\u540d\u7a7a\u95f4"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25100545\/97e27466-e0e5-4600-ab7d-0cdca1ffe406.webp\" alt=\"python\u5982\u4f55\u67e5\u770b\u547d\u540d\u7a7a\u95f4\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c\u67e5\u770b\u547d\u540d\u7a7a\u95f4\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528\u5185\u7f6e\u51fd\u6570<code>globals()<\/code>\u3001<code>locals()<\/code>\u3001<code>dir()<\/code>\uff0c\u4ee5\u53ca\u4f7f\u7528\u8c03\u8bd5\u5de5\u5177\u7b49\u3002<code>globals()<\/code>\u7528\u4e8e\u67e5\u770b\u5168\u5c40\u547d\u540d\u7a7a\u95f4\uff0c<code>locals()<\/code>\u7528\u4e8e\u67e5\u770b\u5c40\u90e8\u547d\u540d\u7a7a\u95f4\uff0c<code>dir()<\/code>\u53ef\u4ee5\u5217\u51fa\u5f53\u524d\u4f5c\u7528\u57df\u4e2d\u7684\u6240\u6709\u540d\u79f0\u3002\u8c03\u8bd5\u5de5\u5177\u5982Python\u8c03\u8bd5\u5668\uff08pdb\uff09\u4e5f\u53ef\u4ee5\u7528\u4e8e\u6df1\u5165\u67e5\u770b\u548c\u63a7\u5236\u547d\u540d\u7a7a\u95f4\u3002<\/strong>\u5728\u8fd9\u4e9b\u65b9\u6cd5\u4e2d\uff0c\u4f7f\u7528<code>dir()<\/code>\u662f\u6700\u5e38\u89c1\u548c\u76f4\u89c2\u7684\u65b9\u5f0f\uff0c\u56e0\u4e3a\u5b83\u80fd\u591f\u5feb\u901f\u5217\u51fa\u6240\u6709\u53ef\u7528\u7684\u53d8\u91cf\u548c\u51fd\u6570\u540d\uff0c\u5e2e\u52a9\u5f00\u53d1\u8005\u7406\u89e3\u5f53\u524d\u7684\u4ee3\u7801\u73af\u5883\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4e86\u89e3Python\u7684\u547d\u540d\u7a7a\u95f4<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u547d\u540d\u7a7a\u95f4\u662f\u4e00\u4e2a\u4ece\u540d\u79f0\u5230\u5bf9\u8c61\u7684\u6620\u5c04\u3002\u6240\u6709\u7684\u53d8\u91cf\u540d\u90fd\u5b58\u5728\u4e8e\u67d0\u4e2a\u547d\u540d\u7a7a\u95f4\u4e2d\u3002Python\u4e2d\u7684\u547d\u540d\u7a7a\u95f4\u5206\u4e3a\u56db\u7c7b\uff1a\u5185\u7f6e\u547d\u540d\u7a7a\u95f4\u3001\u5168\u5c40\u547d\u540d\u7a7a\u95f4\u3001\u5c40\u90e8\u547d\u540d\u7a7a\u95f4\u548c\u5c01\u95ed\u547d\u540d\u7a7a\u95f4\u3002<\/p>\n<\/p>\n<ol>\n<li>\u5185\u7f6e\u547d\u540d\u7a7a\u95f4<\/li>\n<\/ol>\n<p><p>\u5185\u7f6e\u547d\u540d\u7a7a\u95f4\u5305\u542bPython\u89e3\u91ca\u5668\u542f\u52a8\u65f6\u81ea\u52a8\u52a0\u8f7d\u7684\u6240\u6709\u5185\u7f6e\u51fd\u6570\u548c\u5f02\u5e38\u3002\u8fd9\u4e9b\u547d\u540d\u7a7a\u95f4\u5728\u6574\u4e2a\u7a0b\u5e8f\u7684\u751f\u547d\u5468\u671f\u5185\u90fd\u5b58\u5728\uff0c\u5e76\u4e14\u53ef\u4ee5\u901a\u8fc7<code>builtins<\/code>\u6a21\u5757\u8fdb\u884c\u8bbf\u95ee\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u5168\u5c40\u547d\u540d\u7a7a\u95f4<\/li>\n<\/ol>\n<p><p>\u5168\u5c40\u547d\u540d\u7a7a\u95f4\u5305\u62ec\u7a0b\u5e8f\u7ea7\u522b\u5b9a\u4e49\u7684\u53d8\u91cf\u548c\u51fd\u6570\u3002\u5b83\u4eec\u901a\u5e38\u5728\u6a21\u5757\u7ea7\u522b\u4e0a\u5b9a\u4e49\uff0c\u5e76\u5728\u6a21\u5757\u7684\u6574\u4e2a\u751f\u547d\u5468\u671f\u5185\u53ef\u7528\u3002\u4f7f\u7528<code>globals()<\/code>\u51fd\u6570\u53ef\u4ee5\u67e5\u770b\u5168\u5c40\u547d\u540d\u7a7a\u95f4\u4e2d\u7684\u5185\u5bb9\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li>\u5c40\u90e8\u547d\u540d\u7a7a\u95f4<\/li>\n<\/ol>\n<p><p>\u5c40\u90e8\u547d\u540d\u7a7a\u95f4\u662f\u5728\u51fd\u6570\u8c03\u7528\u65f6\u521b\u5efa\u7684\uff0c\u5305\u542b\u51fd\u6570\u5185\u90e8\u5b9a\u4e49\u7684\u53d8\u91cf\u548c\u53c2\u6570\u3002\u51fd\u6570\u6267\u884c\u5b8c\u6bd5\u540e\uff0c\u5c40\u90e8\u547d\u540d\u7a7a\u95f4\u4f1a\u88ab\u9500\u6bc1\u3002\u53ef\u4ee5\u4f7f\u7528<code>locals()<\/code>\u51fd\u6570\u5728\u51fd\u6570\u5185\u90e8\u67e5\u770b\u5c40\u90e8\u547d\u540d\u7a7a\u95f4\u3002<\/p>\n<\/p>\n<ol start=\"4\">\n<li>\u5c01\u95ed\u547d\u540d\u7a7a\u95f4<\/li>\n<\/ol>\n<p><p>\u5c01\u95ed\u547d\u540d\u7a7a\u95f4\u662f\u5728\u5d4c\u5957\u51fd\u6570\u4e2d\uff0c\u5916\u90e8\u51fd\u6570\u7684\u5c40\u90e8\u547d\u540d\u7a7a\u95f4\u3002\u5b83\u4eec\u5728\u5185\u90e8\u51fd\u6570\u4e2d\u662f\u53ef\u8bbf\u95ee\u7684\uff0c\u4f46\u4e0d\u80fd\u4fee\u6539\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u67e5\u770b\u547d\u540d\u7a7a\u95f4<\/p>\n<\/p>\n<ol>\n<li>\u4f7f\u7528<code>globals()<\/code>\u51fd\u6570<\/li>\n<\/ol>\n<p><p><code>globals()<\/code>\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u5b57\u5178\uff0c\u5305\u542b\u5168\u5c40\u547d\u540d\u7a7a\u95f4\u4e2d\u7684\u6240\u6709\u53d8\u91cf\u548c\u51fd\u6570\u3002\u901a\u8fc7\u904d\u5386\u8fd9\u4e2a\u5b57\u5178\uff0c\u4f60\u53ef\u4ee5\u67e5\u770b\u5f53\u524d\u5168\u5c40\u547d\u540d\u7a7a\u95f4\u4e2d\u7684\u6240\u6709\u5185\u5bb9\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">a = 10<\/p>\n<p>b = 20<\/p>\n<p>def print_globals():<\/p>\n<p>    print(globals())<\/p>\n<p>print_globals()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c<code>print_globals()<\/code>\u51fd\u6570\u4f1a\u6253\u5370\u51fa\u5168\u5c40\u547d\u540d\u7a7a\u95f4\u4e2d\u7684\u6240\u6709\u53d8\u91cf\uff0c\u5305\u62ec<code>a<\/code>\u548c<code>b<\/code>\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u4f7f\u7528<code>locals()<\/code>\u51fd\u6570<\/li>\n<\/ol>\n<p><p><code>locals()<\/code>\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u5b57\u5178\uff0c\u5305\u542b\u5c40\u90e8\u547d\u540d\u7a7a\u95f4\u4e2d\u7684\u6240\u6709\u53d8\u91cf\u548c\u53c2\u6570\u3002\u5b83\u901a\u5e38\u5728\u51fd\u6570\u5185\u90e8\u4f7f\u7528\uff0c\u4ee5\u67e5\u770b\u8be5\u51fd\u6570\u7684\u5c40\u90e8\u547d\u540d\u7a7a\u95f4\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def test_function(x, y):<\/p>\n<p>    z = x + y<\/p>\n<p>    print(locals())<\/p>\n<p>test_function(5, 10)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>test_function()<\/code>\u4f1a\u6253\u5370\u51fa\u5c40\u90e8\u547d\u540d\u7a7a\u95f4\u4e2d\u7684\u53d8\u91cf\u548c\u53c2\u6570\uff0c\u5305\u62ec<code>x<\/code>\u3001<code>y<\/code>\u548c<code>z<\/code>\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li>\u4f7f\u7528<code>dir()<\/code>\u51fd\u6570<\/li>\n<\/ol>\n<p><p><code>dir()<\/code>\u51fd\u6570\u7528\u4e8e\u5217\u51fa\u6307\u5b9a\u6a21\u5757\u6216\u5f53\u524d\u4f5c\u7528\u57df\u4e2d\u7684\u6240\u6709\u540d\u79f0\u3002\u5b83\u662f\u67e5\u770b\u547d\u540d\u7a7a\u95f4\u4e2d\u53ef\u7528\u540d\u79f0\u7684\u6700\u5e38\u7528\u65b9\u6cd5\u4e4b\u4e00\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<p>print(dir())<\/p>\n<p>print(dir(math))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c<code>dir()<\/code>\u51fd\u6570\u4f1a\u5217\u51fa\u5f53\u524d\u4f5c\u7528\u57df\u4e2d\u7684\u6240\u6709\u540d\u79f0\uff0c\u800c<code>dir(math)<\/code>\u4f1a\u5217\u51fa<code>math<\/code>\u6a21\u5757\u4e2d\u7684\u6240\u6709\u540d\u79f0\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528\u8c03\u8bd5\u5de5\u5177\u67e5\u770b\u547d\u540d\u7a7a\u95f4<\/p>\n<\/p>\n<ol>\n<li>\u4f7f\u7528Python\u8c03\u8bd5\u5668\uff08pdb\uff09<\/li>\n<\/ol>\n<p><p>Python\u8c03\u8bd5\u5668\uff08pdb\uff09\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u68c0\u67e5\u548c\u63a7\u5236\u7a0b\u5e8f\u7684\u6267\u884c\u8fc7\u7a0b\u3002\u4f60\u53ef\u4ee5\u5728\u8c03\u8bd5\u4f1a\u8bdd\u4e2d\u4f7f\u7528<code>p locals<\/code>\u548c<code>p globals<\/code>\u547d\u4ee4\u67e5\u770b\u5c40\u90e8\u548c\u5168\u5c40\u547d\u540d\u7a7a\u95f4\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pdb<\/p>\n<p>def test_function(x, y):<\/p>\n<p>    z = x + y<\/p>\n<p>    pdb.set_trace()<\/p>\n<p>    return z<\/p>\n<p>test_function(5, 10)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u7a0b\u5e8f\u4f1a\u5728<code>pdb.set_trace()<\/code>\u5904\u6682\u505c\uff0c\u4f60\u53ef\u4ee5\u5728\u8c03\u8bd5\u4f1a\u8bdd\u4e2d\u8f93\u5165<code>p locals()<\/code>\u67e5\u770b\u5c40\u90e8\u547d\u540d\u7a7a\u95f4\uff0c\u8f93\u5165<code>p globals()<\/code>\u67e5\u770b\u5168\u5c40\u547d\u540d\u7a7a\u95f4\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u4f7f\u7528IDE\u8c03\u8bd5\u5de5\u5177<\/li>\n<\/ol>\n<p><p>\u5927\u591a\u6570\u73b0\u4ee3IDE\uff08\u5982PyCharm\u3001VSCode\uff09\u90fd\u63d0\u4f9b\u4e86\u5185\u7f6e\u7684\u8c03\u8bd5\u5de5\u5177\u3002\u4f60\u53ef\u4ee5\u5728\u8c03\u8bd5\u4f1a\u8bdd\u4e2d\u8f7b\u677e\u67e5\u770b\u548c\u4fee\u6539\u547d\u540d\u7a7a\u95f4\u4e2d\u7684\u53d8\u91cf\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u5e94\u7528\u573a\u666f\u548c\u5b9e\u8df5<\/p>\n<\/p>\n<ol>\n<li>\u8c03\u8bd5\u4ee3\u7801<\/li>\n<\/ol>\n<p><p>\u67e5\u770b\u547d\u540d\u7a7a\u95f4\u662f\u8c03\u8bd5\u4ee3\u7801\u7684\u4e00\u4e2a\u91cd\u8981\u6b65\u9aa4\u3002\u5f53\u7a0b\u5e8f\u8fd0\u884c\u4e0d\u7b26\u5408\u9884\u671f\u65f6\uff0c\u68c0\u67e5\u547d\u540d\u7a7a\u95f4\u53ef\u4ee5\u5e2e\u52a9\u4f60\u8bc6\u522b\u672a\u521d\u59cb\u5316\u7684\u53d8\u91cf\u3001\u547d\u540d\u51b2\u7a81\u6216\u610f\u5916\u7684\u503c\u4fee\u6539\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u7406\u89e3\u4ee3\u7801\u7ed3\u6784<\/li>\n<\/ol>\n<p><p>\u67e5\u770b\u547d\u540d\u7a7a\u95f4\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u7406\u89e3\u4ee3\u7801\u7684\u7ed3\u6784\u548c\u4f9d\u8d56\u5173\u7cfb\uff0c\u5c24\u5176\u662f\u5728\u5904\u7406\u590d\u6742\u7684\u6a21\u5757\u6216\u9879\u76ee\u65f6\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li>\u6559\u5b66\u548c\u5b66\u4e60<\/li>\n<\/ol>\n<p><p>\u4e86\u89e3\u547d\u540d\u7a7a\u95f4\u7684\u6982\u5ff5\u548c\u5982\u4f55\u67e5\u770b\u5b83\u4eec\u5bf9\u4e8e\u5b66\u4e60Python\u81f3\u5173\u91cd\u8981\u3002\u8fd9\u4e0d\u4ec5\u5e2e\u52a9\u5b66\u751f\u638c\u63e1Python\u7684\u57fa\u672c\u539f\u7406\uff0c\u8fd8\u80fd\u63d0\u9ad8\u4ed6\u4eec\u7684\u8c03\u8bd5\u548c\u95ee\u9898\u89e3\u51b3\u80fd\u529b\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u6ce8\u610f\u4e8b\u9879<\/p>\n<\/p>\n<ol>\n<li>\u547d\u540d\u7a7a\u95f4\u7684\u751f\u547d\u5468\u671f<\/li>\n<\/ol>\n<p><p>\u7406\u89e3\u547d\u540d\u7a7a\u95f4\u7684\u751f\u547d\u5468\u671f\u662f\u5173\u952e\u3002\u5c40\u90e8\u547d\u540d\u7a7a\u95f4\u5728\u51fd\u6570\u6267\u884c\u5b8c\u6bd5\u540e\u4f1a\u88ab\u9500\u6bc1\uff0c\u800c\u5168\u5c40\u547d\u540d\u7a7a\u95f4\u5728\u7a0b\u5e8f\u7ed3\u675f\u65f6\u624d\u4f1a\u88ab\u9500\u6bc1\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u4fee\u6539\u547d\u540d\u7a7a\u95f4<\/li>\n<\/ol>\n<p><p>\u867d\u7136\u53ef\u4ee5\u901a\u8fc7\u5b57\u5178\u64cd\u4f5c\u4fee\u6539\u547d\u540d\u7a7a\u95f4\u4e2d\u7684\u53d8\u91cf\uff0c\u4f46\u8fd9\u79cd\u505a\u6cd5\u53ef\u80fd\u5bfc\u81f4\u4ee3\u7801\u96be\u4ee5\u7ef4\u62a4\u548c\u8c03\u8bd5\u3002\u5efa\u8bae\u5c3d\u91cf\u907f\u514d\u76f4\u63a5\u64cd\u4f5c\u547d\u540d\u7a7a\u95f4\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li>\u547d\u540d\u51b2\u7a81<\/li>\n<\/ol>\n<p><p>\u547d\u540d\u51b2\u7a81\u662f\u547d\u540d\u7a7a\u95f4\u4e2d\u7684\u4e00\u4e2a\u5e38\u89c1\u95ee\u9898\u3002\u4e3a\u4e86\u907f\u514d\u51b2\u7a81\uff0c\u5efa\u8bae\u4f7f\u7528\u6a21\u5757\u548c\u51fd\u6570\u5c01\u88c5\u53d8\u91cf\uff0c\u5e76\u91c7\u7528\u6709\u610f\u4e49\u7684\u53d8\u91cf\u540d\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u76f8\u4fe1\u4f60\u5df2\u7ecf\u5bf9\u5982\u4f55\u67e5\u770bPython\u7684\u547d\u540d\u7a7a\u95f4\u6709\u4e86\u6df1\u5165\u7684\u7406\u89e3\u3002\u719f\u7ec3\u638c\u63e1\u8fd9\u4e9b\u6280\u5de7\u5c06\u6781\u5927\u5730\u63d0\u9ad8\u4f60\u7684\u7f16\u7a0b\u6548\u7387\u548c\u4ee3\u7801\u8d28\u91cf\u3002\u65e0\u8bba\u662f\u5728\u8c03\u8bd5\u8fd8\u662f\u5728\u5f00\u53d1\u4e2d\uff0c\u67e5\u770b\u547d\u540d\u7a7a\u95f4\u90fd\u662f\u4e00\u9879\u5fc5\u5907\u6280\u80fd\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u67e5\u770b\u5f53\u524d\u547d\u540d\u7a7a\u95f4\u7684\u5185\u5bb9\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684<code>locals()<\/code>\u548c<code>globals()<\/code>\u51fd\u6570\u6765\u67e5\u770b\u5f53\u524d\u547d\u540d\u7a7a\u95f4\u7684\u5185\u5bb9\u3002<code>locals()<\/code>\u8fd4\u56de\u5f53\u524d\u5c40\u90e8\u4f5c\u7528\u57df\u7684\u547d\u540d\u7a7a\u95f4\uff0c\u800c<code>globals()<\/code>\u8fd4\u56de\u5168\u5c40\u547d\u540d\u7a7a\u95f4\u3002\u4f8b\u5982\uff0c\u5728\u4e00\u4e2a\u51fd\u6570\u5185\u90e8\u8c03\u7528<code>locals()<\/code>\u53ef\u4ee5\u770b\u5230\u8be5\u51fd\u6570\u5185\u5b9a\u4e49\u7684\u6240\u6709\u53d8\u91cf\u53ca\u5176\u503c\uff0c\u800c\u5728\u6a21\u5757\u5c42\u7ea7\u8c03\u7528<code>globals()<\/code>\u5219\u4f1a\u5217\u51fa\u6574\u4e2a\u6a21\u5757\u7684\u6240\u6709\u5168\u5c40\u53d8\u91cf\u3002<\/p>\n<p><strong>\u547d\u540d\u7a7a\u95f4\u7684\u4f5c\u7528\u662f\u4ec0\u4e48\uff1f<\/strong><br \/>\u547d\u540d\u7a7a\u95f4\u7528\u4e8e\u9632\u6b62\u547d\u540d\u51b2\u7a81\uff0c\u5b83\u662f\u4e00\u4e2a\u5bb9\u5668\uff0c\u7528\u4e8e\u5b58\u50a8\u53d8\u91cf\u540d\u548c\u5bf9\u8c61\u4e4b\u95f4\u7684\u6620\u5c04\u5173\u7cfb\u3002\u5728Python\u4e2d\uff0c\u4e0d\u540c\u7684\u547d\u540d\u7a7a\u95f4\u53ef\u4ee5\u5b58\u5728\u4e8e\u4e0d\u540c\u7684\u4f5c\u7528\u57df\u4e2d\uff0c\u4f8b\u5982\u5c40\u90e8\u547d\u540d\u7a7a\u95f4\u3001\u5168\u5c40\u547d\u540d\u7a7a\u95f4\u548c\u5185\u5efa\u547d\u540d\u7a7a\u95f4\u3002\u901a\u8fc7\u547d\u540d\u7a7a\u95f4\uff0cPython\u80fd\u591f\u6709\u6548\u7ba1\u7406\u53d8\u91cf\u7684\u751f\u547d\u5468\u671f\u548c\u53ef\u8bbf\u95ee\u6027\uff0c\u4ece\u800c\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728\u8c03\u8bd5\u65f6\u67e5\u770b\u7279\u5b9a\u547d\u540d\u7a7a\u95f4\u7684\u53d8\u91cf\uff1f<\/strong><br \/>\u5728\u8c03\u8bd5Python\u4ee3\u7801\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u8c03\u8bd5\u5de5\u5177\uff08\u5982pdb\uff09\u6765\u67e5\u770b\u7279\u5b9a\u547d\u540d\u7a7a\u95f4\u7684\u53d8\u91cf\u3002\u5728\u8c03\u8bd5\u5668\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>print()<\/code>\u51fd\u6570\u7ed3\u5408<code>locals()<\/code>\u6216<code>globals()<\/code>\u6765\u68c0\u67e5\u5f53\u524d\u7684\u53d8\u91cf\u72b6\u6001\u3002\u6b64\u5916\uff0c\u8bb8\u591aIDE\uff08\u5982PyCharm\u6216VSCode\uff09\u63d0\u4f9b\u4e86\u53ef\u89c6\u5316\u7684\u8c03\u8bd5\u529f\u80fd\uff0c\u4f7f\u60a8\u80fd\u591f\u8f7b\u677e\u67e5\u770b\u4e0d\u540c\u547d\u540d\u7a7a\u95f4\u4e2d\u7684\u53d8\u91cf\u53ca\u5176\u503c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u67e5\u770b\u547d\u540d\u7a7a\u95f4\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528\u5185\u7f6e\u51fd\u6570globals()\u3001locals()\u3001dir()\uff0c\u4ee5\u53ca\u4f7f\u7528 [&hellip;]","protected":false},"author":3,"featured_media":957165,"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\/957161"}],"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=957161"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/957161\/revisions"}],"predecessor-version":[{"id":957166,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/957161\/revisions\/957166"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/957165"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=957161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=957161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=957161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}