{"id":954782,"date":"2024-12-27T02:03:51","date_gmt":"2024-12-26T18:03:51","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/954782.html"},"modified":"2024-12-27T02:03:54","modified_gmt":"2024-12-26T18:03:54","slug":"python%e5%a6%82%e4%bd%95%e6%9f%a5%e7%9c%8b%e5%86%85%e5%ad%98%e7%bb%86%e8%8a%82","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/954782.html","title":{"rendered":"python\u5982\u4f55\u67e5\u770b\u5185\u5b58\u7ec6\u8282"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25094857\/27fb3038-2af8-4394-9b4d-6850fc558125.webp\" alt=\"python\u5982\u4f55\u67e5\u770b\u5185\u5b58\u7ec6\u8282\" \/><\/p>\n<p><p> \u5f00\u5934\u6bb5\u843d\uff1a<\/p>\n<\/p>\n<p><p>\u8981\u67e5\u770bPython\u7a0b\u5e8f\u7684\u5185\u5b58\u7ec6\u8282\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u5de5\u5177\u548c\u5e93\uff0c\u5982<strong>memory-profiler\u3001psutil\u3001objgraph<\/strong>\u7b49\u3002\u5176\u4e2d\uff0cmemory-profiler\u662f\u4e00\u4e2a\u4e13\u95e8\u7528\u4e8e\u5206\u6790Python\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u901a\u8fc7\u88c5\u9970\u5668\u548c\u547d\u4ee4\u884c\u67e5\u770b\u5185\u5b58\u6d88\u8017\uff1bpsutil\u662f\u4e00\u4e2a\u8de8\u5e73\u53f0\u5e93\uff0c\u53ef\u4ee5\u83b7\u53d6\u7cfb\u7edf\u548c\u8fdb\u7a0b\u7ea7\u522b\u7684\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\uff1b\u800cobjgraph\u5219\u53ef\u4ee5\u5e2e\u52a9\u5206\u6790Python\u5bf9\u8c61\u7684\u5f15\u7528\u548c\u5185\u5b58\u6cc4\u6f0f\u60c5\u51b5\u3002<strong>\u4f7f\u7528memory-profiler\u662f\u6700\u76f4\u63a5\u6709\u6548\u7684\u65b9\u6cd5<\/strong>\uff0c\u56e0\u4e3a\u5b83\u53ef\u4ee5\u901a\u8fc7\u7b80\u5355\u7684\u547d\u4ee4\u884c\u547d\u4ee4\u6216\u5728\u4ee3\u7801\u4e2d\u6dfb\u52a0\u88c5\u9970\u5668\u7684\u65b9\u5f0f\uff0c\u63d0\u4f9b\u51fd\u6570\u7ea7\u522b\u7684\u5185\u5b58\u4f7f\u7528\u4fe1\u606f\u3002\u901a\u8fc7\u8fd9\u4e9b\u5de5\u5177\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u8bc6\u522b\u548c\u4f18\u5316Python\u7a0b\u5e8f\u4e2d\u7684\u5185\u5b58\u6d88\u8017\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001MEMORY-PROFILER\u7684\u4f7f\u7528<\/p>\n<\/p>\n<p><p>Memory-profiler\u662f\u4e00\u4e2a\u7528\u4e8e\u76d1\u63a7Python\u7a0b\u5e8f\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u7684\u6a21\u5757\u3002\u5b83\u53ef\u4ee5\u7cbe\u786e\u5730\u544a\u8bc9\u4f60\u5728\u4ee3\u7801\u7684\u54ea\u4e9b\u884c\u5185\u5b58\u4f7f\u7528\u6700\u591a\u3002\u4f7f\u7528\u5b83\u7684\u4e00\u4e2a\u5e38\u89c1\u65b9\u6cd5\u662f\u4f7f\u7528\u88c5\u9970\u5668@profile\u6765\u76d1\u63a7\u51fd\u6570\u3002<\/p>\n<\/p>\n<ol>\n<li>\u5b89\u88c5\u548c\u57fa\u672c\u7528\u6cd5<\/li>\n<\/ol>\n<p><p>\u8981\u4f7f\u7528memory-profiler\uff0c\u9996\u5148\u9700\u8981\u5b89\u88c5\u5b83\u3002\u53ef\u4ee5\u901a\u8fc7pip\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install memory-profiler<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u5728Python\u4ee3\u7801\u4e2d\u4f7f\u7528\u88c5\u9970\u5668@profile\u6765\u76d1\u63a7\u7279\u5b9a\u51fd\u6570\u7684\u5185\u5b58\u4f7f\u7528\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from memory_profiler import profile<\/p>\n<p>@profile<\/p>\n<p>def my_function():<\/p>\n<p>    a = [i for i in range(10000)]<\/p>\n<p>    return a<\/p>\n<p>if __name__ == &quot;__m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n__&quot;:<\/p>\n<p>    my_function()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd0\u884c\u4ee3\u7801\u65f6\uff0cmemory-profiler\u4f1a\u8f93\u51fa\u5185\u5b58\u4f7f\u7528\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u5305\u62ec\u6bcf\u4e00\u884c\u4ee3\u7801\u7684\u5185\u5b58\u6d88\u8017\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u547d\u4ee4\u884c\u5de5\u5177<\/li>\n<\/ol>\n<p><p>memory-profiler\u8fd8\u63d0\u4f9b\u4e86\u4e00\u4e2a\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u53ef\u4ee5\u76f4\u63a5\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u3002\u8981\u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">mprof run my_script.py<\/p>\n<p>mprof plot<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0a\u8ff0\u547d\u4ee4\u5c06\u751f\u6210\u4e00\u4e2a\u5185\u5b58\u4f7f\u7528\u7684\u56fe\u8868\uff0c\u5e2e\u52a9\u5f00\u53d1\u8005\u76f4\u89c2\u5730\u4e86\u89e3\u7a0b\u5e8f\u7684\u5185\u5b58\u6d88\u8017\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001PSUTIL\u5e93\u7684\u4f7f\u7528<\/p>\n<\/p>\n<p><p>psutil\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u8de8\u5e73\u53f0\u5e93\uff0c\u53ef\u4ee5\u7528\u4e8e\u76d1\u63a7\u7cfb\u7edf\u548c\u8fdb\u7a0b\u7684\u8d44\u6e90\u4f7f\u7528\u60c5\u51b5\uff0c\u5305\u62ecCPU\u3001\u5185\u5b58\u3001\u78c1\u76d8\u3001\u7f51\u7edc\u7b49\u3002<\/p>\n<\/p>\n<ol>\n<li>\u5b89\u88c5\u548c\u83b7\u53d6\u7cfb\u7edf\u5185\u5b58\u4fe1\u606f<\/li>\n<\/ol>\n<p><p>\u9996\u5148\uff0c\u5b89\u88c5psutil\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install psutil<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u53ef\u4ee5\u4f7f\u7528psutil\u83b7\u53d6\u7cfb\u7edf\u7684\u5185\u5b58\u4fe1\u606f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import psutil<\/p>\n<p>def get_memory_info():<\/p>\n<p>    memory = psutil.virtual_memory()<\/p>\n<p>    print(f&quot;Total Memory: {memory.total \/ (1024  3):.2f} GB&quot;)<\/p>\n<p>    print(f&quot;Available Memory: {memory.available \/ (1024  3):.2f} GB&quot;)<\/p>\n<p>    print(f&quot;Used Memory: {memory.used \/ (1024  3):.2f} GB&quot;)<\/p>\n<p>    print(f&quot;Memory Usage: {memory.percent}%&quot;)<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    get_memory_info()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u83b7\u53d6\u8fdb\u7a0b\u5185\u5b58\u4fe1\u606f<\/li>\n<\/ol>\n<p><p>psutil\u8fd8\u53ef\u4ee5\u7528\u4e8e\u83b7\u53d6\u7279\u5b9a\u8fdb\u7a0b\u7684\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import psutil<\/p>\n<p>def get_process_memory_info(pid):<\/p>\n<p>    process = psutil.Process(pid)<\/p>\n<p>    memory_info = process.memory_info()<\/p>\n<p>    print(f&quot;Process ID: {pid}&quot;)<\/p>\n<p>    print(f&quot;RSS: {memory_info.rss \/ (1024  2):.2f} MB&quot;)<\/p>\n<p>    print(f&quot;VMS: {memory_info.vms \/ (1024  2):.2f} MB&quot;)<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    get_process_memory_info(psutil.Process().pid)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e09\u3001OBJGRAPH\u7684\u4f7f\u7528<\/p>\n<\/p>\n<p><p>objgraph\u662f\u4e00\u4e2a\u7528\u4e8e\u5206\u6790Python\u5bf9\u8c61\u5f15\u7528\u548c\u5185\u5b58\u6cc4\u6f0f\u60c5\u51b5\u7684\u5de5\u5177\u3002\u5b83\u7279\u522b\u9002\u7528\u4e8e\u68c0\u67e5\u590d\u6742\u5e94\u7528\u4e2d\u7684\u5185\u5b58\u6cc4\u6f0f\u95ee\u9898\u3002<\/p>\n<\/p>\n<ol>\n<li>\u5b89\u88c5\u548c\u57fa\u672c\u7528\u6cd5<\/li>\n<\/ol>\n<p><p>\u5b89\u88c5objgraph\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install objgraph<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f7f\u7528objgraph\u53ef\u4ee5\u7ed8\u5236\u5bf9\u8c61\u5f15\u7528\u56fe\uff0c\u5e2e\u52a9\u8bc6\u522b\u5185\u5b58\u6cc4\u6f0f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import objgraph<\/p>\n<p>def test_objgraph():<\/p>\n<p>    a = []<\/p>\n<p>    b = [a, [a], {&#39;a&#39;: a}]<\/p>\n<p>    objgraph.show_refs([b], filename=&#39;refs.png&#39;)<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    test_objgraph()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0a\u8ff0\u4ee3\u7801\u5c06\u751f\u6210\u4e00\u4e2a\u56fe\u50cf\u6587\u4ef6&#39;refs.png&#39;\uff0c\u663e\u793a\u5bf9\u8c61b\u53ca\u5176\u5f15\u7528\u5173\u7cfb\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u68c0\u67e5\u5185\u5b58\u6cc4\u6f0f<\/li>\n<\/ol>\n<p><p>objgraph\u53ef\u4ee5\u7528\u4e8e\u68c0\u67e5\u5185\u5b58\u6cc4\u6f0f\uff0c\u901a\u8fc7\u6bd4\u8f83\u4e0d\u540c\u65f6\u95f4\u70b9\u7684\u5bf9\u8c61\u6570\u91cf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import objgraph<\/p>\n<p>def memory_leak_example():<\/p>\n<p>    a = []<\/p>\n<p>    objgraph.show_growth(limit=3)<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    memory_leak_example()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd0\u884c\u4ee3\u7801\u540e\uff0cobjgraph\u4f1a\u663e\u793a\u54ea\u4e9b\u5bf9\u8c61\u5728\u5185\u5b58\u4e2d\u589e\u957f\u6700\u5feb\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001PYTHON\u5185\u7f6e\u5de5\u5177<\/p>\n<\/p>\n<p><p>\u9664\u4e86\u7b2c\u4e09\u65b9\u5e93\uff0cPython\u8fd8\u63d0\u4f9b\u4e86\u4e00\u4e9b\u5185\u7f6e\u5de5\u5177\u6765\u5e2e\u52a9\u5f00\u53d1\u8005\u5206\u6790\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u3002<\/p>\n<\/p>\n<ol>\n<li>sys\u6a21\u5757<\/li>\n<\/ol>\n<p><p>sys\u6a21\u5757\u63d0\u4f9b\u4e86\u83b7\u53d6Python\u89e3\u91ca\u5668\u7684\u5185\u5b58\u4f7f\u7528\u4fe1\u606f\u7684\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import sys<\/p>\n<p>def get_object_size(obj):<\/p>\n<p>    size = sys.getsizeof(obj)<\/p>\n<p>    print(f&quot;Object size: {size} bytes&quot;)<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    get_object_size([1, 2, 3, 4, 5])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>tracemalloc\u6a21\u5757<\/li>\n<\/ol>\n<p><p>tracemalloc\u662fPython\u5185\u7f6e\u7684\u4e00\u4e2a\u5185\u5b58\u8ddf\u8e2a\u6a21\u5757\uff0c\u5141\u8bb8\u5f00\u53d1\u8005\u8ddf\u8e2a\u5185\u5b58\u5206\u914d\uff0c\u5e76\u67e5\u627e\u5185\u5b58\u6cc4\u6f0f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import tracemalloc<\/p>\n<p>def start_memory_trace():<\/p>\n<p>    tracemalloc.start()<\/p>\n<p>def display_top_memory_usage():<\/p>\n<p>    snapshot = tracemalloc.take_snapshot()<\/p>\n<p>    top_stats = snapshot.statistics(&#39;lineno&#39;)<\/p>\n<p>    print(&quot;[ Top 10 Memory Usage ]&quot;)<\/p>\n<p>    for stat in top_stats[:10]:<\/p>\n<p>        print(stat)<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    start_memory_trace()<\/p>\n<p>    # Your code here<\/p>\n<p>    display_top_memory_usage()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e94\u3001\u4f18\u5316PYTHON\u5185\u5b58\u4f7f\u7528\u7684\u5efa\u8bae<\/p>\n<\/p>\n<p><p>\u5728\u5206\u6790\u5185\u5b58\u4f7f\u7528\u4e4b\u540e\uff0c\u5f00\u53d1\u8005\u901a\u5e38\u9700\u8981\u91c7\u53d6\u4e00\u4e9b\u63aa\u65bd\u6765\u4f18\u5316Python\u7a0b\u5e8f\u7684\u5185\u5b58\u6d88\u8017\u3002<\/p>\n<\/p>\n<ol>\n<li>\u4f7f\u7528\u751f\u6210\u5668<\/li>\n<\/ol>\n<p><p>\u751f\u6210\u5668\u662f\u4e00\u79cd\u5728\u9700\u8981\u65f6\u624d\u751f\u6210\u6570\u636e\u7684\u7279\u6b8a\u51fd\u6570\uff0c\u4e0e\u4e00\u6b21\u6027\u521b\u5efa\u6574\u4e2a\u6570\u636e\u5217\u8868\u76f8\u6bd4\uff0c\u5b83\u4eec\u53ef\u4ee5\u663e\u8457\u51cf\u5c11\u5185\u5b58\u6d88\u8017\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def my_generator():<\/p>\n<p>    for i in range(10000):<\/p>\n<p>        yield i<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    for value in my_generator():<\/p>\n<p>        print(value)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u51cf\u5c11\u5168\u5c40\u53d8\u91cf\u7684\u4f7f\u7528<\/li>\n<\/ol>\n<p><p>\u5168\u5c40\u53d8\u91cf\u4f1a\u4e00\u76f4\u5360\u7528\u5185\u5b58\uff0c\u76f4\u5230\u7a0b\u5e8f\u7ed3\u675f\u3002\u901a\u8fc7\u5c06\u53d8\u91cf\u7684\u4f5c\u7528\u57df\u9650\u5236\u5728\u51fd\u6570\u6216\u7c7b\u4e2d\uff0c\u53ef\u4ee5\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u5185\u5b58\u6d88\u8017\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li>\u4f7f\u7528\u5185\u5b58\u6c60<\/li>\n<\/ol>\n<p><p>\u4f7f\u7528\u5185\u5b58\u6c60\u53ef\u4ee5\u51cf\u5c11\u9891\u7e41\u7684\u5185\u5b58\u5206\u914d\u548c\u91ca\u653e\u64cd\u4f5c\uff0c\u63d0\u9ad8\u7a0b\u5e8f\u7684\u8fd0\u884c\u6548\u7387\u3002<\/p>\n<\/p>\n<p><p>\u603b\u7ed3\u800c\u8a00\uff0c\u5206\u6790\u548c\u4f18\u5316Python\u7a0b\u5e8f\u7684\u5185\u5b58\u4f7f\u7528\u4e0d\u4ec5\u4ec5\u662f\u4e3a\u4e86\u51cf\u5c11\u5185\u5b58\u6d88\u8017\uff0c\u4e5f\u662f\u4e3a\u4e86\u63d0\u9ad8\u7a0b\u5e8f\u7684\u6027\u80fd\u548c\u7a33\u5b9a\u6027\u3002\u901a\u8fc7\u4f7f\u7528\u4e0a\u8ff0\u5de5\u5177\u548c\u6280\u672f\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u66f4\u597d\u5730\u4e86\u89e3\u548c\u63a7\u5236Python\u7a0b\u5e8f\u7684\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u68c0\u67e5\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>sys<\/code>\u6a21\u5757\u548c<code>resource<\/code>\u6a21\u5757\u6765\u68c0\u67e5\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u3002\u901a\u8fc7<code>sys.getsizeof()<\/code>\u51fd\u6570\u53ef\u4ee5\u83b7\u53d6\u5bf9\u8c61\u7684\u5185\u5b58\u5360\u7528\uff0c\u800c\u4f7f\u7528<code>resource.getrusage(resource.RUSAGE_SELF).ru_maxrss<\/code>\u53ef\u4ee5\u83b7\u53d6\u5f53\u524d\u8fdb\u7a0b\u7684\u6700\u5927\u5185\u5b58\u4f7f\u7528\u91cf\u3002\u6b64\u5916\uff0c\u8fd8\u6709\u7b2c\u4e09\u65b9\u5e93\u5982<code>psutil<\/code>\uff0c\u53ef\u4ee5\u63d0\u4f9b\u66f4\u5168\u9762\u7684\u5185\u5b58\u4fe1\u606f\u3002<\/p>\n<p><strong>Python\u4e2d\u6709\u54ea\u4e9b\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u5206\u6790\u5185\u5b58\u6cc4\u6f0f\uff1f<\/strong><br \/>Python\u63d0\u4f9b\u4e86\u591a\u4e2a\u5de5\u5177\u6765\u5e2e\u52a9\u5206\u6790\u5185\u5b58\u6cc4\u6f0f\u95ee\u9898\u3002<code>objgraph<\/code>\u662f\u4e00\u4e2a\u975e\u5e38\u6709\u7528\u7684\u5e93\uff0c\u53ef\u4ee5\u7ed8\u5236\u5bf9\u8c61\u4e4b\u95f4\u7684\u5173\u7cfb\u56fe\uff0c\u5e2e\u52a9\u8bc6\u522b\u5185\u5b58\u6cc4\u6f0f\u7684\u6e90\u5934\u3002<code>memory_profiler<\/code>\u5219\u5141\u8bb8\u9010\u884c\u5206\u6790\u4ee3\u7801\u7684\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\uff0c\u5e2e\u52a9\u5f00\u53d1\u8005\u627e\u5230\u5185\u5b58\u4f7f\u7528\u7684\u9ad8\u5cf0\u70b9\u3002\u4f7f\u7528<code>tracemalloc<\/code>\u6a21\u5757\u4e5f\u53ef\u4ee5\u8ffd\u8e2a\u5185\u5b58\u5206\u914d\uff0c\u8bc6\u522b\u6f5c\u5728\u7684\u5185\u5b58\u6cc4\u6f0f\u3002<\/p>\n<p><strong>\u5982\u4f55\u4f18\u5316Python\u7a0b\u5e8f\u7684\u5185\u5b58\u4f7f\u7528\uff1f<\/strong><br \/>\u4f18\u5316Python\u7a0b\u5e8f\u7684\u5185\u5b58\u4f7f\u7528\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\u3002\u4f7f\u7528\u751f\u6210\u5668\u4ee3\u66ff\u5217\u8868\u53ef\u4ee5\u51cf\u5c11\u5185\u5b58\u5360\u7528\uff0c\u540c\u65f6\u5c3d\u91cf\u907f\u514d\u4f7f\u7528\u5168\u5c40\u53d8\u91cf\uff0c\u4ee5\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u5185\u5b58\u5360\u7528\u3002\u9009\u62e9\u5408\u9002\u7684\u6570\u636e\u7ed3\u6784\u4e5f\u81f3\u5173\u91cd\u8981\uff0c\u4f8b\u5982\u4f7f\u7528<code>array<\/code>\u6216<code>numpy<\/code>\u6570\u7ec4\u6765\u5b58\u50a8\u5927\u91cf\u6570\u503c\u6570\u636e\uff0c\u80fd\u591f\u663e\u8457\u964d\u4f4e\u5185\u5b58\u9700\u6c42\u3002\u6b64\u5916\uff0c\u5b9a\u671f\u4f7f\u7528<code>del<\/code>\u8bed\u53e5\u5220\u9664\u4e0d\u518d\u4f7f\u7528\u7684\u5bf9\u8c61\uff0c\u4e5f\u6709\u52a9\u4e8e\u91ca\u653e\u5185\u5b58\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5f00\u5934\u6bb5\u843d\uff1a \u8981\u67e5\u770bPython\u7a0b\u5e8f\u7684\u5185\u5b58\u7ec6\u8282\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u5de5\u5177\u548c\u5e93\uff0c\u5982memory-profiler\u3001psut [&hellip;]","protected":false},"author":3,"featured_media":954785,"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\/954782"}],"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=954782"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/954782\/revisions"}],"predecessor-version":[{"id":954786,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/954782\/revisions\/954786"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/954785"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=954782"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=954782"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=954782"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}