{"id":935097,"date":"2024-12-26T18:46:36","date_gmt":"2024-12-26T10:46:36","guid":{"rendered":""},"modified":"2024-12-26T18:46:38","modified_gmt":"2024-12-26T10:46:38","slug":"python%e5%a6%82%e4%bd%95%e5%88%a0%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/935097.html","title":{"rendered":"python\u5982\u4f55\u5220\u6587\u4ef6"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25071857\/6268c122-b677-40e6-ba11-cd3f6b716aa3.webp\" alt=\"python\u5982\u4f55\u5220\u6587\u4ef6\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u5220\u9664\u6587\u4ef6\u53ef\u4ee5\u4f7f\u7528os\u6a21\u5757\u4e2d\u7684remove()\u51fd\u6570\u6216pathlib\u6a21\u5757\u4e2d\u7684unlink()\u65b9\u6cd5\u3002os.remove()\u9002\u7528\u4e8e\u4efb\u4f55\u64cd\u4f5c\u7cfb\u7edf\uff0cpathlib.unlink()\u5219\u63d0\u4f9b\u4e86\u4e00\u79cd\u66f4\u9762\u5411\u5bf9\u8c61\u7684\u65b9\u5f0f\uff0c\u9002\u5408Python 3.4\u53ca\u4ee5\u4e0a\u7248\u672c\u3002os.remove()\u9700\u8981\u63d0\u4f9b\u6587\u4ef6\u7684\u5b8c\u6574\u8def\u5f84\uff0c\u5e76\u4e14\u5728\u5220\u9664\u524d\u6700\u597d\u786e\u8ba4\u6587\u4ef6\u5b58\u5728\uff0c\u4ee5\u907f\u514d\u62a5\u9519\u3002<\/strong><\/p>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u6cd5\u6765\u5220\u9664\u6587\u4ef6\uff0c\u6700\u5e38\u7528\u7684\u662fos\u6a21\u5757\u4e2d\u7684remove()\u51fd\u6570\u3002\u4f7f\u7528os.remove()\u5220\u9664\u6587\u4ef6\u65f6\uff0c\u9996\u5148\u9700\u8981\u5bfc\u5165os\u6a21\u5757\uff0c\u7136\u540e\u8c03\u7528os.remove()\u5e76\u4f20\u5165\u6587\u4ef6\u8def\u5f84\u5373\u53ef\u3002os\u6a21\u5757\u4e2d\u7684remove()\u975e\u5e38\u9002\u5408\u5904\u7406\u7b80\u5355\u7684\u6587\u4ef6\u5220\u9664\u4efb\u52a1\uff0c\u4f46\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6700\u597d\u5728\u5220\u9664\u524d\u68c0\u67e5\u6587\u4ef6\u662f\u5426\u5b58\u5728\uff0c\u4ee5\u514d\u5f15\u53d1FileNotFoundError\u9519\u8bef\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>file_path = &#39;example.txt&#39;<\/p>\n<p>if os.path.exists(file_path):<\/p>\n<p>    os.remove(file_path)<\/p>\n<p>else:<\/p>\n<p>    print(f&quot;The file {file_path} does not exist.&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u786e\u4fdd\u53ea\u6709\u5728\u6587\u4ef6\u5b58\u5728\u65f6\u624d\u5c1d\u8bd5\u5220\u9664\u5b83\uff0c\u907f\u514d\u4e86\u4e0d\u5fc5\u8981\u7684\u9519\u8bef\u3002<\/p>\n<\/p>\n<hr>\n<p><p>\u4e00\u3001PYTHON\u5220\u9664\u6587\u4ef6\u7684\u65b9\u6cd5<\/p>\n<\/p>\n<p><p>Python\u4e2d\u7684\u6587\u4ef6\u5220\u9664\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u6cd5\u5b9e\u73b0\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><p>1\u3001\u4f7f\u7528os\u6a21\u5757\u7684remove()\u51fd\u6570<\/p>\n<\/p>\n<p><p>os\u6a21\u5757\u662fPython\u6807\u51c6\u5e93\u7684\u4e00\u90e8\u5206\uff0c\u63d0\u4f9b\u4e86\u4e0e\u64cd\u4f5c\u7cfb\u7edf\u4ea4\u4e92\u7684\u529f\u80fd\u3002os.remove()\u51fd\u6570\u7528\u4e8e\u5220\u9664\u6587\u4ef6\uff0c\u5b83\u9700\u8981\u4f20\u5165\u4e00\u4e2a\u6587\u4ef6\u8def\u5f84\u4f5c\u4e3a\u53c2\u6570\u3002\u4f7f\u7528\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>file_path = &#39;example.txt&#39;<\/p>\n<p>os.remove(file_path)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>2\u3001\u4f7f\u7528os\u6a21\u5757\u7684unlink()\u51fd\u6570<\/p>\n<\/p>\n<p><p>os\u6a21\u5757\u4e2d\u8fd8\u6709\u4e00\u4e2aunlink()\u51fd\u6570\uff0c\u4e0eremove()\u529f\u80fd\u76f8\u540c\u3002\u5b9e\u9645\u4e0a\uff0cos.unlink()\u662fos.remove()\u7684\u522b\u540d\uff0c\u56e0\u6b64\u4e24\u8005\u53ef\u4ee5\u4e92\u6362\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>file_path = &#39;example.txt&#39;<\/p>\n<p>os.unlink(file_path)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>3\u3001\u4f7f\u7528pathlib\u6a21\u5757\u7684Path.unlink()\u65b9\u6cd5<\/p>\n<\/p>\n<p><p>pathlib\u6a21\u5757\u63d0\u4f9b\u4e86\u9762\u5411\u5bf9\u8c61\u7684\u6587\u4ef6\u7cfb\u7edf\u8def\u5f84\u64cd\u4f5c\u3002\u5b83\u5f15\u5165\u4e86Path\u5bf9\u8c61\uff0cPath\u5bf9\u8c61\u7684unlink()\u65b9\u6cd5\u53ef\u4ee5\u7528\u6765\u5220\u9664\u6587\u4ef6\u3002pathlib\u6a21\u5757\u66f4\u9002\u5408Python 3.4\u53ca\u4ee5\u4e0a\u7248\u672c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from pathlib import Path<\/p>\n<p>file_path = Path(&#39;example.txt&#39;)<\/p>\n<p>file_path.unlink()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e8c\u3001\u5220\u9664\u6587\u4ef6\u524d\u7684\u68c0\u67e5<\/p>\n<\/p>\n<p><p>\u5728\u5220\u9664\u6587\u4ef6\u4e4b\u524d\uff0c\u68c0\u67e5\u6587\u4ef6\u662f\u5426\u5b58\u5728\u662f\u4e00\u4e2a\u826f\u597d\u7684\u7f16\u7a0b\u5b9e\u8df5\u3002\u8fd9\u53ef\u4ee5\u9632\u6b62\u7a0b\u5e8f\u5728\u5c1d\u8bd5\u5220\u9664\u4e0d\u5b58\u5728\u7684\u6587\u4ef6\u65f6\u5d29\u6e83\u3002os.path\u6a21\u5757\u63d0\u4f9b\u4e86exists()\u51fd\u6570\u7528\u4e8e\u68c0\u67e5\u6587\u4ef6\u662f\u5426\u5b58\u5728\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>file_path = &#39;example.txt&#39;<\/p>\n<p>if os.path.exists(file_path):<\/p>\n<p>    os.remove(file_path)<\/p>\n<p>else:<\/p>\n<p>    print(f&quot;The file {file_path} does not exist.&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>pathlib\u6a21\u5757\u7684Path\u5bf9\u8c61\u540c\u6837\u63d0\u4f9b\u4e86exists()\u65b9\u6cd5\u6765\u68c0\u67e5\u6587\u4ef6\u5b58\u5728\u6027\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from pathlib import Path<\/p>\n<p>file_path = Path(&#39;example.txt&#39;)<\/p>\n<p>if file_path.exists():<\/p>\n<p>    file_path.unlink()<\/p>\n<p>else:<\/p>\n<p>    print(f&quot;The file {file_path} does not exist.&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e09\u3001\u5904\u7406\u6587\u4ef6\u5220\u9664\u4e2d\u7684\u5f02\u5e38<\/p>\n<\/p>\n<p><p>\u5728\u5c1d\u8bd5\u5220\u9664\u6587\u4ef6\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u5404\u79cd\u5f02\u5e38\uff0c\u5982\u6587\u4ef6\u4e0d\u5b58\u5728\u3001\u6743\u9650\u4e0d\u8db3\u7b49\u3002Python\u63d0\u4f9b\u4e86\u5f02\u5e38\u5904\u7406\u673a\u5236\uff0c\u53ef\u4ee5\u901a\u8fc7try-except\u5757\u6765\u6355\u83b7\u5e76\u5904\u7406\u8fd9\u4e9b\u5f02\u5e38\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>file_path = &#39;example.txt&#39;<\/p>\n<p>try:<\/p>\n<p>    os.remove(file_path)<\/p>\n<p>except FileNotFoundError:<\/p>\n<p>    print(f&quot;The file {file_path} does not exist.&quot;)<\/p>\n<p>except PermissionError:<\/p>\n<p>    print(f&quot;Permission denied to delete {file_path}.&quot;)<\/p>\n<p>except Exception as e:<\/p>\n<p>    print(f&quot;An error occurred: {e}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f7f\u7528pathlib\u6a21\u5757\u65f6\uff0c\u5904\u7406\u5f02\u5e38\u7684\u65b9\u5f0f\u7c7b\u4f3c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from pathlib import Path<\/p>\n<p>file_path = Path(&#39;example.txt&#39;)<\/p>\n<p>try:<\/p>\n<p>    file_path.unlink()<\/p>\n<p>except FileNotFoundError:<\/p>\n<p>    print(f&quot;The file {file_path} does not exist.&quot;)<\/p>\n<p>except PermissionError:<\/p>\n<p>    print(f&quot;Permission denied to delete {file_path}.&quot;)<\/p>\n<p>except Exception as e:<\/p>\n<p>    print(f&quot;An error occurred: {e}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u56db\u3001\u6279\u91cf\u5220\u9664\u6587\u4ef6<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u53ef\u80fd\u9700\u8981\u5220\u9664\u4e00\u7ec4\u6587\u4ef6\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u904d\u5386\u6587\u4ef6\u5217\u8868\u5e76\u9010\u4e2a\u5220\u9664\u6765\u5b9e\u73b0\u3002os.listdir()\u51fd\u6570\u53ef\u4ee5\u5217\u51fa\u76ee\u5f55\u4e2d\u7684\u6240\u6709\u6587\u4ef6\u548c\u5b50\u76ee\u5f55\uff0c\u914d\u5408os.remove()\u6216pathlib\u6a21\u5757\uff0c\u53ef\u4ee5\u5b9e\u73b0\u6279\u91cf\u5220\u9664\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>directory = &#39;example_directory&#39;<\/p>\n<p>for filename in os.listdir(directory):<\/p>\n<p>    file_path = os.path.join(directory, filename)<\/p>\n<p>    try:<\/p>\n<p>        if os.path.isfile(file_path):<\/p>\n<p>            os.remove(file_path)<\/p>\n<p>    except Exception as e:<\/p>\n<p>        print(f&quot;F<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>led to delete {file_path}. Reason: {e}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f7f\u7528pathlib\u6a21\u5757\u53ef\u4ee5\u66f4\u7b80\u6d01\u5730\u5b9e\u73b0\u540c\u6837\u7684\u529f\u80fd\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from pathlib import Path<\/p>\n<p>directory = Path(&#39;example_directory&#39;)<\/p>\n<p>for file_path in directory.iterdir():<\/p>\n<p>    try:<\/p>\n<p>        if file_path.is_file():<\/p>\n<p>            file_path.unlink()<\/p>\n<p>    except Exception as e:<\/p>\n<p>        print(f&quot;Failed to delete {file_path}. Reason: {e}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e94\u3001\u5220\u9664\u53ea\u8bfb\u6587\u4ef6<\/p>\n<\/p>\n<p><p>\u6709\u65f6\uff0c\u6587\u4ef6\u53ef\u80fd\u662f\u53ea\u8bfb\u7684\uff0c\u8fd9\u4f1a\u5bfc\u81f4\u5220\u9664\u64cd\u4f5c\u5931\u8d25\u3002\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528os.chmod()\u51fd\u6570\u4fee\u6539\u6587\u4ef6\u6743\u9650\uff0c\u5148\u5c06\u6587\u4ef6\u8bbe\u7f6e\u4e3a\u53ef\u5199\uff0c\u7136\u540e\u518d\u5220\u9664\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>import stat<\/p>\n<p>file_path = &#39;example.txt&#39;<\/p>\n<p>if os.path.exists(file_path):<\/p>\n<p>    os.chmod(file_path, stat.S_IWRITE)<\/p>\n<p>    os.remove(file_path)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728Linux\u548cmacOS\u7cfb\u7edf\u4e0a\uff0c\u53ef\u4ee5\u4f7f\u7528os.chmod()\u51fd\u6570\u5c06\u6587\u4ef6\u6743\u9650\u4fee\u6539\u4e3a\u53ef\u5199\uff0c\u7136\u540e\u518d\u5220\u9664\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>file_path = &#39;example.txt&#39;<\/p>\n<p>if os.path.exists(file_path):<\/p>\n<p>    os.chmod(file_path, 0o777)<\/p>\n<p>    os.remove(file_path)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u516d\u3001\u5220\u9664\u6587\u4ef6\u540e\u7684\u9519\u8bef\u5904\u7406<\/p>\n<\/p>\n<p><p>\u5728\u5220\u9664\u6587\u4ef6\u540e\uff0c\u6709\u65f6\u53ef\u80fd\u9700\u8981\u6267\u884c\u4e00\u4e9b\u6e05\u7406\u64cd\u4f5c\u6216\u8bb0\u5f55\u65e5\u5fd7\u3002Python\u7684\u5f02\u5e38\u5904\u7406\u673a\u5236\u53ef\u4ee5\u5e2e\u52a9\u5904\u7406\u5220\u9664\u6587\u4ef6\u540e\u7684\u9519\u8bef\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>file_path = &#39;example.txt&#39;<\/p>\n<p>try:<\/p>\n<p>    os.remove(file_path)<\/p>\n<p>except Exception as e:<\/p>\n<p>    print(f&quot;Failed to delete {file_path}. Reason: {e}&quot;)<\/p>\n<p>else:<\/p>\n<p>    print(f&quot;{file_path} was successfully deleted.&quot;)<\/p>\n<p>finally:<\/p>\n<p>    # Perform any necessary cleanup or logging here<\/p>\n<p>    print(&quot;Cleanup complete.&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e03\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u8fdb\u884c\u6587\u4ef6\u5220\u9664<\/p>\n<\/p>\n<p><p>\u9664\u4e86Python\u6807\u51c6\u5e93\uff0c\u7b2c\u4e09\u65b9\u5e93shutil\u4e5f\u63d0\u4f9b\u4e86\u5220\u9664\u6587\u4ef6\u548c\u76ee\u5f55\u7684\u529f\u80fd\u3002shutil\u6a21\u5757\u7684rmtree()\u51fd\u6570\u53ef\u4ee5\u7528\u6765\u5220\u9664\u76ee\u5f55\u53ca\u5176\u5185\u5bb9\u3002\u8fd9\u5728\u9700\u8981\u5220\u9664\u6574\u4e2a\u76ee\u5f55\u53ca\u5176\u6240\u6709\u6587\u4ef6\u65f6\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import shutil<\/p>\n<p>directory = &#39;example_directory&#39;<\/p>\n<p>try:<\/p>\n<p>    shutil.rmtree(directory)<\/p>\n<p>except Exception as e:<\/p>\n<p>    print(f&quot;Failed to delete directory {directory}. Reason: {e}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u603b\u7ed3\u8d77\u6765\uff0cPython\u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u6cd5\u6765\u5220\u9664\u6587\u4ef6\u3002\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u53d6\u51b3\u4e8e\u5177\u4f53\u7684\u9700\u6c42\u548c\u9879\u76ee\u73af\u5883\u3002\u65e0\u8bba\u4f7f\u7528\u54ea\u79cd\u65b9\u6cd5\uff0c\u5728\u5220\u9664\u6587\u4ef6\u524d\u68c0\u67e5\u6587\u4ef6\u662f\u5426\u5b58\u5728\uff0c\u5e76\u5728\u5220\u9664\u8fc7\u7a0b\u4e2d\u5904\u7406\u53ef\u80fd\u7684\u5f02\u5e38\uff0c\u662f\u786e\u4fdd\u7a0b\u5e8f\u7a33\u5b9a\u6027\u548c\u53ef\u9760\u6027\u7684\u5173\u952e\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u5220\u9664\u7279\u5b9a\u6587\u4ef6\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7<code>os<\/code>\u6a21\u5757\u7684<code>remove()<\/code>\u51fd\u6570\u6765\u5220\u9664\u7279\u5b9a\u6587\u4ef6\u3002\u9996\u5148\uff0c\u9700\u5bfc\u5165<code>os<\/code>\u6a21\u5757\uff0c\u7136\u540e\u4f7f\u7528<code>os.remove(&#39;\u6587\u4ef6\u8def\u5f84&#39;)<\/code>\u6765\u5220\u9664\u6240\u9700\u6587\u4ef6\u3002\u786e\u4fdd\u5728\u5220\u9664\u6587\u4ef6\u4e4b\u524d\uff0c\u6587\u4ef6\u8def\u5f84\u662f\u6b63\u786e\u7684\uff0c\u5e76\u4e14\u60a8\u6709\u6743\u9650\u8fdb\u884c\u5220\u9664\u64cd\u4f5c\u3002<\/p>\n<p><strong>\u5728\u5220\u9664\u6587\u4ef6\u65f6\uff0c\u5982\u4f55\u5904\u7406\u4e0d\u5b58\u5728\u7684\u6587\u4ef6\uff1f<\/strong><br \/>\u5728\u5c1d\u8bd5\u5220\u9664\u4e00\u4e2a\u6587\u4ef6\u65f6\uff0c\u5982\u679c\u6587\u4ef6\u4e0d\u5b58\u5728\uff0cPython\u4f1a\u629b\u51fa<code>FileNotFoundError<\/code>\u5f02\u5e38\u3002\u4e3a\u4e86\u907f\u514d\u7a0b\u5e8f\u56e0\u8fd9\u4e00\u5f02\u5e38\u800c\u4e2d\u65ad\uff0c\u53ef\u4ee5\u4f7f\u7528<code>try...except<\/code>\u8bed\u53e5\u6765\u6355\u83b7\u8be5\u5f02\u5e38\uff0c\u5e76\u5728\u5f02\u5e38\u53d1\u751f\u65f6\u63d0\u4f9b\u7528\u6237\u53cb\u597d\u7684\u63d0\u793a\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u5728<code>except<\/code>\u90e8\u5206\u8f93\u51fa\u201c\u6587\u4ef6\u4e0d\u5b58\u5728\uff0c\u65e0\u6cd5\u5220\u9664\u201d\u3002<\/p>\n<p><strong>\u6709\u6ca1\u6709\u65b9\u6cd5\u53ef\u4ee5\u6279\u91cf\u5220\u9664\u591a\u4e2a\u6587\u4ef6\uff1f<\/strong><br \/>Python\u63d0\u4f9b\u4e86\u7075\u6d3b\u7684\u65b9\u5f0f\u6765\u6279\u91cf\u5220\u9664\u6587\u4ef6\u3002\u53ef\u4ee5\u4f7f\u7528<code>os<\/code>\u6a21\u5757\u7ed3\u5408<code>os.listdir()<\/code>\u51fd\u6570\u5217\u51fa\u76ee\u5f55\u4e2d\u7684\u6240\u6709\u6587\u4ef6\uff0c\u5e76\u901a\u8fc7\u5faa\u73af\u7ed3\u6784\u9010\u4e2a\u5220\u9664\u3002\u53ea\u9700\u786e\u4fdd\u5728\u5220\u9664\u4e4b\u524d\u5bf9\u6587\u4ef6\u540d\u8fdb\u884c\u9002\u5f53\u7684\u8fc7\u6ee4\uff0c\u786e\u4fdd\u53ea\u5220\u9664\u60a8\u60f3\u8981\u7684\u6587\u4ef6\uff0c\u4ee5\u907f\u514d\u8bef\u5220\u91cd\u8981\u6570\u636e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u5220\u9664\u6587\u4ef6\u53ef\u4ee5\u4f7f\u7528os\u6a21\u5757\u4e2d\u7684remove()\u51fd\u6570\u6216pathlib\u6a21\u5757\u4e2d\u7684unlink()\u65b9\u6cd5\u3002 [&hellip;]","protected":false},"author":3,"featured_media":935099,"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\/935097"}],"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=935097"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/935097\/revisions"}],"predecessor-version":[{"id":935100,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/935097\/revisions\/935100"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/935099"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=935097"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=935097"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=935097"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}