{"id":930994,"date":"2024-12-26T17:27:58","date_gmt":"2024-12-26T09:27:58","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/930994.html"},"modified":"2024-12-26T17:27:59","modified_gmt":"2024-12-26T09:27:59","slug":"python%e5%a6%82%e4%bd%95%e5%8a%a0%e8%bd%bdpath","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/930994.html","title":{"rendered":"python\u5982\u4f55\u52a0\u8f7dpath"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25065515\/3ff3f886-ed54-40bd-8a9f-aa76e38ce572.webp\" alt=\"python\u5982\u4f55\u52a0\u8f7dpath\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u52a0\u8f7d\u8def\u5f84\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528os\u6a21\u5757\u548cpathlib\u6a21\u5757\u3001sys\u6a21\u5757\u6765\u7ba1\u7406\u548c\u64cd\u4f5c\u6587\u4ef6\u8def\u5f84\u3002os\u6a21\u5757\u63d0\u4f9b\u4e86\u8bb8\u591a\u4e0e\u64cd\u4f5c\u7cfb\u7edf\u4ea4\u4e92\u7684\u529f\u80fd\uff0c\u800cpathlib\u6a21\u5757\u63d0\u4f9b\u4e86\u4e00\u79cd\u66f4\u52a0\u9762\u5411\u5bf9\u8c61\u7684\u65b9\u6cd5\u6765\u5904\u7406\u6587\u4ef6\u8def\u5f84\u3002sys\u6a21\u5757\u5219\u7528\u4e8e\u52a8\u6001\u5730\u6dfb\u52a0\u8def\u5f84\u5230Python\u7684\u641c\u7d22\u8def\u5f84\u4e2d\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528OS\u6a21\u5757\u52a0\u8f7d\u8def\u5f84<\/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\u65b9\u6cd5\u3002\u4f7f\u7528os\u6a21\u5757\u53ef\u4ee5\u65b9\u4fbf\u5730\u64cd\u4f5c\u6587\u4ef6\u548c\u76ee\u5f55\uff0c\u5305\u62ec\u52a0\u8f7d\u8def\u5f84\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u83b7\u53d6\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528<code>os.getcwd()<\/code>\u65b9\u6cd5\u53ef\u4ee5\u83b7\u53d6\u5f53\u524d\u7684\u5de5\u4f5c\u76ee\u5f55\u8def\u5f84\u3002\u8fd9\u5728\u9700\u8981\u77e5\u9053\u5f53\u524dPython\u811a\u672c\u8fd0\u884c\u4f4d\u7f6e\u65f6\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>current_directory = os.getcwd()<\/p>\n<p>print(f&quot;\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\uff1a{current_directory}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u83b7\u53d6\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u540e\uff0c\u53ef\u4ee5\u57fa\u4e8e\u6b64\u8def\u5f84\u8fdb\u884c\u76f8\u5bf9\u8def\u5f84\u7684\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u66f4\u6539\u5de5\u4f5c\u76ee\u5f55<\/strong><\/p>\n<\/p>\n<p><p>\u6709\u65f6\u5019\u9700\u8981\u6539\u53d8\u5f53\u524d\u7684\u5de5\u4f5c\u76ee\u5f55\uff0c\u53ef\u4ee5\u4f7f\u7528<code>os.chdir()<\/code>\u65b9\u6cd5\u3002\u5b83\u5141\u8bb8\u4f60\u6307\u5b9a\u4e00\u4e2a\u65b0\u7684\u8def\u5f84\uff0c\u8fd9\u6837\u540e\u7eed\u7684\u6587\u4ef6\u64cd\u4f5c\u5c31\u4f1a\u57fa\u4e8e\u65b0\u76ee\u5f55\u8fdb\u884c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">new_directory = &#39;\/path\/to\/new\/directory&#39;<\/p>\n<p>os.chdir(new_directory)<\/p>\n<p>print(f&quot;\u5de5\u4f5c\u76ee\u5f55\u5df2\u66f4\u6539\u4e3a\uff1a{os.getcwd()}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u66f4\u6539\u5de5\u4f5c\u76ee\u5f55\u540e\uff0c\u8981\u6ce8\u610f\u786e\u4fdd\u65b0\u8def\u5f84\u662f\u6709\u6548\u7684\uff0c\u4ee5\u514d\u5bfc\u81f4\u6587\u4ef6\u64cd\u4f5c\u5931\u8d25\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8def\u5f84\u62fc\u63a5<\/strong><\/p>\n<\/p>\n<p><p>\u62fc\u63a5\u8def\u5f84\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u9700\u6c42\uff0c\u4f7f\u7528<code>os.path.join()<\/code>\u65b9\u6cd5\u53ef\u4ee5\u65b9\u4fbf\u5730\u5c06\u591a\u4e2a\u8def\u5f84\u7ec4\u4ef6\u7ec4\u5408\u6210\u4e00\u4e2a\u5b8c\u6574\u8def\u5f84\uff0c\u907f\u514d\u624b\u52a8\u6dfb\u52a0\u8def\u5f84\u5206\u9694\u7b26\u7684\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">file_name = &#39;example.txt&#39;<\/p>\n<p>full_path = os.path.join(current_directory, file_name)<\/p>\n<p>print(f&quot;\u5b8c\u6574\u6587\u4ef6\u8def\u5f84\uff1a{full_path}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u5728\u8de8\u5e73\u53f0\u5f00\u53d1\u65f6\u5c24\u4e3a\u91cd\u8981\uff0c\u56e0\u4e3a\u5b83\u80fd\u6839\u636e\u64cd\u4f5c\u7cfb\u7edf\u81ea\u52a8\u9009\u62e9\u6b63\u786e\u7684\u8def\u5f84\u5206\u9694\u7b26\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u68c0\u67e5\u8def\u5f84\u6709\u6548\u6027<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u8fdb\u884c\u6587\u4ef6\u64cd\u4f5c\u4e4b\u524d\uff0c\u68c0\u67e5\u8def\u5f84\u7684\u6709\u6548\u6027\u662f\u4e2a\u597d\u4e60\u60ef\u3002\u4f7f\u7528<code>os.path.exists()<\/code>\u548c<code>os.path.isfile()<\/code>\u65b9\u6cd5\u53ef\u4ee5\u5224\u65ad\u8def\u5f84\u6216\u6587\u4ef6\u662f\u5426\u5b58\u5728\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">if os.path.exists(full_path):<\/p>\n<p>    print(&quot;\u8def\u5f84\u6709\u6548\uff0c\u53ef\u4ee5\u8fdb\u884c\u6587\u4ef6\u64cd\u4f5c&quot;)<\/p>\n<p>else:<\/p>\n<p>    print(&quot;\u8def\u5f84\u65e0\u6548\uff0c\u8bf7\u68c0\u67e5\u8def\u5f84&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u53ef\u4ee5\u907f\u514d\u5728\u8def\u5f84\u65e0\u6548\u65f6\u6267\u884c\u6587\u4ef6\u64cd\u4f5c\uff0c\u4ece\u800c\u51cf\u5c11\u9519\u8bef\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u4f7f\u7528Pathlib\u6a21\u5757\u52a0\u8f7d\u8def\u5f84<\/p>\n<\/p>\n<p><p>Pathlib\u6a21\u5757\u5728Python 3.4\u4e2d\u5f15\u5165\uff0c\u63d0\u4f9b\u4e86\u4e00\u79cd\u9762\u5411\u5bf9\u8c61\u7684\u65b9\u6cd5\u6765\u5904\u7406\u6587\u4ef6\u548c\u76ee\u5f55\u8def\u5f84\u3002\u76f8\u6bd4os\u6a21\u5757\uff0cPathlib\u66f4\u76f4\u89c2\u4e14\u529f\u80fd\u5f3a\u5927\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u521b\u5efa\u8def\u5f84\u5bf9\u8c61<\/strong><\/p>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528Pathlib\u6a21\u5757\u4e2d\u7684<code>Path<\/code>\u7c7b\u6765\u521b\u5efa\u8def\u5f84\u5bf9\u8c61\u3002\u8def\u5f84\u5bf9\u8c61\u53ef\u4ee5\u662f\u6587\u4ef6\u8def\u5f84\u6216\u76ee\u5f55\u8def\u5f84\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from pathlib import Path<\/p>\n<p>current_directory = Path.cwd()<\/p>\n<p>print(f&quot;\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\uff1a{current_directory}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f7f\u7528<code>Path<\/code>\u7c7b\u521b\u5efa\u8def\u5f84\u5bf9\u8c61\u540e\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u8def\u5f84\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8def\u5f84\u7ec4\u5408<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528<code>\/<\/code>\u8fd0\u7b97\u7b26\u53ef\u4ee5\u8f7b\u677e\u5730\u7ec4\u5408\u8def\u5f84\uff0c\u800c\u65e0\u9700\u62c5\u5fc3\u8def\u5f84\u5206\u9694\u7b26\u7684\u95ee\u9898\u3002\u8fd9\u4f7f\u5f97\u8def\u5f84\u64cd\u4f5c\u66f4\u52a0\u76f4\u89c2\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">file_name = &#39;example.txt&#39;<\/p>\n<p>full_path = current_directory \/ file_name<\/p>\n<p>print(f&quot;\u5b8c\u6574\u6587\u4ef6\u8def\u5f84\uff1a{full_path}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u5f0f\u4e0d\u4ec5\u7b80\u6d01\uff0c\u800c\u4e14\u63d0\u9ad8\u4e86\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8def\u5f84\u68c0\u67e5<\/strong><\/p>\n<\/p>\n<p><p>Pathlib\u6a21\u5757\u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u6cd5\u6765\u68c0\u67e5\u8def\u5f84\u7684\u72b6\u6001\uff0c\u5982<code>exists()<\/code>\u3001<code>is_file()<\/code>\u548c<code>is_dir()<\/code>\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">if full_path.exists():<\/p>\n<p>    print(&quot;\u8def\u5f84\u6709\u6548\uff0c\u53ef\u4ee5\u8fdb\u884c\u6587\u4ef6\u64cd\u4f5c&quot;)<\/p>\n<p>else:<\/p>\n<p>    print(&quot;\u8def\u5f84\u65e0\u6548\uff0c\u8bf7\u68c0\u67e5\u8def\u5f84&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f7f\u7528\u8fd9\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u8f7b\u677e\u5730\u9a8c\u8bc1\u8def\u5f84\u7684\u6709\u6548\u6027\u548c\u7c7b\u578b\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6587\u4ef6\u64cd\u4f5c<\/strong><\/p>\n<\/p>\n<p><p>\u9664\u4e86\u8def\u5f84\u64cd\u4f5c\uff0cPathlib\u8fd8\u63d0\u4f9b\u4e86\u65b9\u4fbf\u7684\u6587\u4ef6\u64cd\u4f5c\u65b9\u6cd5\uff0c\u5982\u8bfb\u53d6\u6587\u4ef6\u5185\u5bb9\u3001\u5199\u5165\u6587\u4ef6\u3001\u5220\u9664\u6587\u4ef6\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">if full_path.is_file():<\/p>\n<p>    content = full_path.read_text()<\/p>\n<p>    print(&quot;\u6587\u4ef6\u5185\u5bb9\uff1a&quot;)<\/p>\n<p>    print(content)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f7f\u7528Pathlib\u8fdb\u884c\u6587\u4ef6\u64cd\u4f5c\uff0c\u4ee3\u7801\u66f4\u52a0\u7b80\u6d01\u4e14\u6613\u4e8e\u7ef4\u62a4\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u4f7f\u7528SYS\u6a21\u5757\u52a0\u8f7d\u8def\u5f84<\/p>\n<\/p>\n<p><p>sys\u6a21\u5757\u63d0\u4f9b\u4e86\u4e00\u4e9b\u4e0ePython\u89e3\u91ca\u5668\u4ea4\u4e92\u7684\u529f\u80fd\uff0c\u53ef\u4ee5\u52a8\u6001\u5730\u4fee\u6539Python\u7684\u6a21\u5757\u641c\u7d22\u8def\u5f84\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u67e5\u770b\u5f53\u524d\u641c\u7d22\u8def\u5f84<\/strong><\/p>\n<\/p>\n<p><p>\u53ef\u4ee5\u901a\u8fc7\u8bbf\u95ee<code>sys.path<\/code>\u6765\u67e5\u770b\u5f53\u524dPython\u7684\u6a21\u5757\u641c\u7d22\u8def\u5f84\u5217\u8868\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import sys<\/p>\n<p>print(&quot;\u5f53\u524d\u6a21\u5757\u641c\u7d22\u8def\u5f84\uff1a&quot;)<\/p>\n<p>for path in sys.path:<\/p>\n<p>    print(path)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e86\u89e3\u5f53\u524d\u7684\u641c\u7d22\u8def\u5f84\u6709\u52a9\u4e8e\u8c03\u8bd5\u6a21\u5757\u5bfc\u5165\u95ee\u9898\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6dfb\u52a0\u81ea\u5b9a\u4e49\u8def\u5f84<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u9700\u8981\u52a0\u8f7d\u5728\u9ed8\u8ba4\u641c\u7d22\u8def\u5f84\u4e4b\u5916\u7684\u6a21\u5757\uff0c\u53ef\u4ee5\u5c06\u65b0\u7684\u8def\u5f84\u6dfb\u52a0\u5230<code>sys.path<\/code>\u4e2d\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">custom_path = &#39;\/path\/to\/custom\/modules&#39;<\/p>\n<p>if custom_path not in sys.path:<\/p>\n<p>    sys.path.append(custom_path)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6dfb\u52a0\u81ea\u5b9a\u4e49\u8def\u5f84\u540e\uff0cPython\u4f1a\u5728\u65b0\u7684\u8def\u5f84\u4e2d\u641c\u7d22\u6a21\u5757\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u786e\u4fdd\u8def\u5f84\u552f\u4e00<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u6dfb\u52a0\u8def\u5f84\u4e4b\u524d\uff0c\u6700\u597d\u68c0\u67e5\u8def\u5f84\u662f\u5426\u5df2\u7ecf\u5b58\u5728\u4e8e<code>sys.path<\/code>\u4e2d\uff0c\u4ee5\u907f\u514d\u91cd\u590d\u6dfb\u52a0\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">if custom_path not in sys.path:<\/p>\n<p>    sys.path.append(custom_path)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u786e\u4fdd\u8def\u5f84\u552f\u4e00\u53ef\u4ee5\u63d0\u9ad8\u6a21\u5757\u641c\u7d22\u7684\u6548\u7387\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u65b9\u6cd5\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u52a0\u8f7d\u548c\u7ba1\u7406Python\u4e2d\u7684\u8def\u5f84\u3002\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u53ef\u9760\u6027\u3002\u65e0\u8bba\u662f\u4f7f\u7528os\u6a21\u5757\u3001pathlib\u6a21\u5757\u8fd8\u662fsys\u6a21\u5757\uff0c\u90fd\u6709\u5176\u5404\u81ea\u7684\u4f18\u52bf\u548c\u5e94\u7528\u573a\u666f\u3002\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u7075\u6d3b\u5730\u7ed3\u5408\u4f7f\u7528\u8fd9\u4e9b\u6a21\u5757\uff0c\u5c06\u5e2e\u52a9\u6211\u4eec\u66f4\u9ad8\u6548\u5730\u8fdb\u884c\u8def\u5f84\u7ba1\u7406\u548c\u6587\u4ef6\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u6dfb\u52a0\u81ea\u5b9a\u4e49\u6a21\u5757\u7684\u8def\u5f84\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>sys<\/code>\u6a21\u5757\u6765\u6dfb\u52a0\u81ea\u5b9a\u4e49\u6a21\u5757\u7684\u8def\u5f84\u3002\u9996\u5148\uff0c\u60a8\u9700\u8981\u5bfc\u5165<code>sys<\/code>\u6a21\u5757\uff0c\u7136\u540e\u4f7f\u7528<code>sys.path.append()<\/code>\u65b9\u6cd5\u5c06\u81ea\u5b9a\u4e49\u8def\u5f84\u6dfb\u52a0\u5230\u6a21\u5757\u641c\u7d22\u8def\u5f84\u4e2d\u3002\u793a\u4f8b\u5982\u4e0b\uff1a  <\/p>\n<pre><code class=\"language-python\">import sys\nsys.path.append(&#39;\/your\/custom\/path&#39;)\n<\/code><\/pre>\n<p>\u8fd9\u6837\uff0cPython\u5c31\u80fd\u591f\u627e\u5230\u60a8\u5728\u6307\u5b9a\u8def\u5f84\u4e0b\u7684\u6a21\u5757\u3002<\/p>\n<p><strong>Python\u662f\u5426\u652f\u6301\u76f8\u5bf9\u8def\u5f84\u52a0\u8f7d\uff1f<\/strong><br \/>\u662f\u7684\uff0cPython\u652f\u6301\u4f7f\u7528\u76f8\u5bf9\u8def\u5f84\u6765\u52a0\u8f7d\u6a21\u5757\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528<code>.<\/code>\u548c<code>..<\/code>\u6765\u8868\u793a\u5f53\u524d\u76ee\u5f55\u548c\u4e0a\u7ea7\u76ee\u5f55\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>from . import module_name<\/code>\u53ef\u4ee5\u4ece\u5f53\u524d\u5305\u4e2d\u5bfc\u5165\u6a21\u5757\uff0c\u800c<code>from ..sub_package import module_name<\/code>\u5219\u53ef\u4ee5\u4ece\u4e0a\u7ea7\u5305\u7684\u5b50\u5305\u4e2d\u5bfc\u5165\u6a21\u5757\u3002<\/p>\n<p><strong>\u5728Jupyter Notebook\u4e2d\u5982\u4f55\u8bbe\u7f6e\u6a21\u5757\u8def\u5f84\uff1f<\/strong><br \/>\u5728Jupyter Notebook\u4e2d\uff0c\u60a8\u540c\u6837\u53ef\u4ee5\u4f7f\u7528<code>sys.path.append()<\/code>\u6765\u6dfb\u52a0\u6a21\u5757\u8def\u5f84\u3002\u60a8\u53ef\u4ee5\u5728Notebook\u7684\u4efb\u610f\u5355\u5143\u683c\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u4ee3\u7801\uff1a  <\/p>\n<pre><code class=\"language-python\">import sys\nsys.path.append(&#39;\/your\/custom\/path&#39;)\n<\/code><\/pre>\n<p>\u8fd9\u6837\uff0c\u60a8\u5c31\u53ef\u4ee5\u5728Notebook\u4e2d\u5bfc\u5165\u81ea\u5b9a\u4e49\u8def\u5f84\u4e0b\u7684\u6a21\u5757\u4e86\u3002\u786e\u4fdd\u5728\u5bfc\u5165\u6a21\u5757\u4e4b\u524d\u6dfb\u52a0\u8def\u5f84\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u52a0\u8f7d\u8def\u5f84\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528os\u6a21\u5757\u548cpathlib\u6a21\u5757\u3001sys\u6a21\u5757\u6765\u7ba1\u7406\u548c\u64cd\u4f5c\u6587\u4ef6\u8def\u5f84\u3002os\u6a21\u5757\u63d0\u4f9b [&hellip;]","protected":false},"author":3,"featured_media":930995,"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\/930994"}],"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=930994"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/930994\/revisions"}],"predecessor-version":[{"id":930996,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/930994\/revisions\/930996"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/930995"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=930994"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=930994"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=930994"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}