{"id":6323,"date":"2021-03-08T03:23:47","date_gmt":"2021-03-07T19:23:47","guid":{"rendered":"https:\/\/vip.fxxkpython.com\/?p=6323"},"modified":"2021-03-08T03:27:46","modified_gmt":"2021-03-07T19:27:46","slug":"python-%e7%88%ac%e9%98%b6%e6%a2%af-%ef%bd%9c-python-%e7%9a%84%e5%9e%83%e5%9c%be%e5%9b%9e%e6%94%b6%e6%98%af%e4%b8%aa%e5%95%a5%e5%95%8a%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/vip.fxxkpython.com\/?p=6323","title":{"rendered":"Python \u722c\u9636\u68af \uff5c Python \u90a3\u4e9b\u6c38\u8fdc\u7528\u4e0d\u5230\u7684\u5bf9\u8c61\uff0c\u6211\u4eec\u79f0\u4e4b\u4e3a\u300c\u5783\u573e\u300d"},"content":{"rendered":"\n<p>\u4eca\u5929\u54b1\u4eec\u6765 <a href=\"https:\/\/vip.fxxkpython.com\/?cat=140\">\u300cPython \u722c\u9636\u68af\u300d<\/a>\uff0c\u6211\u4eec\u77e5\u9053\u4f7f\u7528 Python \u53ef\u4ee5\u521b\u5efa\u5bf9\u8c61\uff0c\u5f53\u6211\u4eec\u53bb\u5f15\u7528\u5b83\u7684\u65f6\u5019\uff0c\u7cfb\u7edf\u4f1a\u5f00\u8f9f\u4e00\u4e2a\u5185\u5b58\u7a7a\u95f4\u5b58\u653e\u5bf9\u8c61\uff0c\u4e0d\u8fc7\u53ef\u80fd\u6709\u4e9b\u5bf9\u8c61\u6211\u4eec\u7528\u5b8c\u4e4b\u540e\uff0c\u6c38\u8fdc\u518d\u4e5f\u4e0d\u4f1a\u53bb\u4f7f\u7528\u4e86\uff0c\u90a3\u8fd9\u5bf9\u8c61\u4e0d\u80fd\u4e00\u76f4\u7559\u5728\u5185\u5b58\u91cc\u8fb9\u5427\uff0c\u5bf9\u8c61\u5df2\u7ecf\u5e9f\u4e86\uff0c\u4e5f\u5c31\u6210\u4e3a\u4e86\u300c\u5783\u573e\u300d\uff0c\u5783\u573e\u8981\u6e05\u7406\u6389\uff0c\u5185\u5b58\u624d\u80fd\u817e\u51fa\u4f4d\u7f6e\u7ed9\u522b\u7684\u7a0b\u5e8f\u4f7f\u7528\u3002<\/p>\n\n\n\n<p>\u90a3\u4e48\uff1a<\/p>\n\n\n\n<h2>Python\u662f\u600e\u4e48\u56de\u6536\u5783\u573e\u7684\uff1f<\/h2>\n\n\n\n<h3>\u5148\u6765\u4e86\u89e3\u4e00\u4e0b\u300c\u5f15\u7528\u6b21\u6570\u300d<\/h3>\n\n\n\n<p>\u5728 Python \u7684\u5185\u7f6e\u6a21\u5757 sys \u6709\u4e00\u4e2a <a href=\"https:\/\/docs.python.org\/3\/library\/sys.html#sys.getrefcount\">getrefcount<\/a> \u65b9\u6cd5\uff0c\u901a\u8fc7\u5b83\uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u5bf9\u8c61\u88ab\u5f15\u7528\u7684\u6b21\u6570\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"1024\" height=\"96\" src=\"https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/03\/\u622a\u5c4f2021-03-08-\u4e0a\u534812.35.18-1024x96.png\" alt=\"\" class=\"wp-image-6324\" srcset=\"https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/03\/\u622a\u5c4f2021-03-08-\u4e0a\u534812.35.18-1024x96.png 1024w, https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/03\/\u622a\u5c4f2021-03-08-\u4e0a\u534812.35.18-300x28.png 300w, https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/03\/\u622a\u5c4f2021-03-08-\u4e0a\u534812.35.18-768x72.png 768w, https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/03\/\u622a\u5c4f2021-03-08-\u4e0a\u534812.35.18-1536x143.png 1536w, https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/03\/\u622a\u5c4f2021-03-08-\u4e0a\u534812.35.18-769x72.png 769w, https:\/\/vip.fxxkpython.com\/wp-content\/uploads\/2021\/03\/\u622a\u5c4f2021-03-08-\u4e0a\u534812.35.18.png 1692w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<p>\u6bd4\u5982\u6211\u4eec\u5b9a\u4e49\u8fd9\u6837\u4e00\u4e2a\u300cs\u300d\uff1a<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;wpum_restrict_type&quot;:&quot;wpum_restrict_type_state&quot;,&quot;wpum_hide_state_in&quot;:false,&quot;wpum_hide_state_out&quot;:false,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">import sys\n\ns = [1, 2, 3]\nprint(sys.getrefcount(s))\n\n-------------------------\n2<\/pre><\/div>\n\n\n\n<p>\u8fd9\u91cc\u5f97\u5230\u7684\u7ed3\u679c\u4e3a 2 \u6b21\u5f15\u7528\uff0c\u5176\u4e2d\u4e00\u6b21\u662f s\uff0c\u4e00\u6b21\u662f getrefcount\u3002<\/p>\n\n\n\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u770b\u770b\u8fd9\u6837\u7684\u4ee3\u7801\uff1a<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;wpum_restrict_type&quot;:&quot;wpum_restrict_type_state&quot;,&quot;wpum_hide_state_in&quot;:false,&quot;wpum_hide_state_out&quot;:false,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">import sys\n\ndef fxxk():\n    s = [1, 2, 3]\n    print(sys.getrefcount(s))\n\nfxxk()\nprint(sys.getrefcount(s))\n\n--------------------------\n\n2\nTraceback (most recent call last):\n  File &quot;main.py&quot;, line 8, in &lt;module&gt;\n    print(sys.getrefcount(s))\nNameError: name 's' is not defined<\/pre><\/div>\n\n\n\n<p>\u5f53\u6211\u4eec\u6267\u884c\u5b8c fxxk \u65b9\u6cd5\u4e4b\u540e\uff0c\u6211\u4eec\u65e0\u6cd5\u518d\u53bb\u5f15\u7528\u5bf9\u8c61 s \u4e86\uff0c\u56e0\u4e3a\u5b83\u5df2\u7ecf\u88ab\u56de\u6536\u3002<\/p>\n\n\n\n<p>\u4e5f\u5c31\u662f\u8bf4\uff0c\u5f53\u6267\u884c\u5b8c fxxk() \u4e4b\u540e\uff0c\u5bf9\u8c61 s \u7684\u5f15\u7528\u6570\u91cf\u4e3a<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%3D6323\">\u767b\u9646<\/a> \u540e\u624d\u53ef\u4ee5\u6d4f\u89c8<\/div>\u8fd9\u91cc\u6211\u4eec\u521b\u5efa\u4e86 handsomeb \u5bf9\u8c61\uff0c\u89c1\u4e00\u4e2a\u5973\u751f\u7231\u4e00\u4e2a\u3002\u3002\u3002\u4e3b\u8981\u662f\u6700\u540e\u4e24\u884c\u4ee3\u7801\uff0c\u5f53\u6211\u4eec\u4f7f\u7528 del handsomeb \u7684\u65f6\u5019\uff0c\u5b9e\u9645\u4e0a\u5c31\u662f\u5c06 handsombe \u8fd9\u4e2a\u5bf9\u8c61\u7ed9\u5220\u9664\u91ca\u653e\u6389\uff0c\u4e0d\u8fc7\u8fd9\u4e2a\u65f6\u5019\u8fd8\u5b58\u5728\u90a3\u4e9b\u548c handsomeb \u7684\u5173\u8054\u5bf9\u8c61 Girl \u4eec\uff0c\u5979\u4eec\u5df2\u7ecf\u6ca1\u6709\u4ec0\u4e48\u7528\u4e86\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 gc.collect()\uff0c\u5c06\u548c handsomeb \u5173\u8054\u7684\u5bf9\u8c61\u4eec\u90fd\u7ed9\u91ca\u653e\u6389\u3002<\/p>\n\n\n\n<p>ok\uff0c\u4ee5\u4e0a\u5c31\u662f\u5c0f\u5e05b\u4eca\u5929\u7ed9\u4f60\u5e26\u6765\u7684\u5206\u4eab\uff0c\u5173\u4e8e Python \u7684\u5783\u573e\u56de\u6536\u95ee\u9898\uff0c\u9762\u8bd5\u4e5f\u5e38\u5e38\u4f1a\u88ab\u95ee\u5230\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u5e2e\u52a9\uff0c\u90a3\u4e48\u6211\u4eec\u4e0b\u56de\u89c1\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u5929\u54b1\u4eec\u6765 \u300cPython \u722c\u9636\u68af\u300d\uff0c\u6211\u4eec\u77e5\u9053\u4f7f\u7528 Python \u53ef\u4ee5\u521b\u5efa\u5bf9\u8c61\uff0c\u5f53\u6211\u4eec\u53bb\u5f15\u7528\u5b83\u7684\u65f6\u5019\uff0c\u7cfb\u7edf\u4f1a\u5f00\u8f9f\u4e00\u4e2a\u5185\u5b58\u7a7a\u95f4\u5b58\u653e\u5bf9\u8c61\uff0c\u4e0d\u8fc7\u53ef\u80fd\u6709\u4e9b\u5bf9\u8c61\u6211\u4eec\u7528\u5b8c\u4e4b\u540e\uff0c\u6c38\u8fdc\u518d\u4e5f\u4e0d\u4f1a\u53bb\u4f7f\u7528\u4e86\uff0c\u90a3\u8fd9\u5bf9\u8c61\u4e0d\u80fd\u4e00\u76f4\u7559\u5728\u5185\u5b58\u91cc\u8fb9\u5427\uff0c\u5bf9\u8c61\u5df2\u7ecf\u5e9f\u4e86\uff0c\u4e5f\u5c31\u6210\u4e3a\u4e86\u300c\u5783\u573e\u300d&hellip;<\/p>\n","protected":false},"author":1,"featured_media":6324,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[140],"tags":[19],"_links":{"self":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/6323"}],"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=6323"}],"version-history":[{"count":2,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/6323\/revisions"}],"predecessor-version":[{"id":6326,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/posts\/6323\/revisions\/6326"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=\/wp\/v2\/media\/6324"}],"wp:attachment":[{"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6323"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6323"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vip.fxxkpython.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}