{"id":1004832,"date":"2024-12-27T10:30:05","date_gmt":"2024-12-27T02:30:05","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1004832.html"},"modified":"2024-12-27T10:30:08","modified_gmt":"2024-12-27T02:30:08","slug":"python%e5%a6%82%e4%bd%95%e6%8d%a2%e5%88%b0%e5%85%b6%e4%bb%96%e7%a3%81%e7%9b%98","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1004832.html","title":{"rendered":"python\u5982\u4f55\u6362\u5230\u5176\u4ed6\u78c1\u76d8"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25081617\/4c109a59-d409-458b-9a6b-41c4c3c643ab.webp\" alt=\"python\u5982\u4f55\u6362\u5230\u5176\u4ed6\u78c1\u76d8\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u5207\u6362\u5230\u5176\u4ed6\u78c1\u76d8\u53ef\u4ee5\u901a\u8fc7\u6539\u53d8\u5de5\u4f5c\u76ee\u5f55\u3001\u4f7f\u7528\u7edd\u5bf9\u8def\u5f84\u3001\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u7b49\u65b9\u5f0f\u5b9e\u73b0<\/strong>\u3002\u5176\u4e2d\uff0c\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u901a\u8fc7<code>os<\/code>\u6a21\u5757\u4e2d\u7684<code>chdir()<\/code>\u51fd\u6570\u6539\u53d8\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5728Python\u4e2d\u5207\u6362\u5230\u5176\u4ed6\u78c1\u76d8\u7684\u591a\u79cd\u65b9\u5f0f\u3002<\/p>\n<\/p>\n<h2><strong>\u4e00\u3001\u6539\u53d8\u5de5\u4f5c\u76ee\u5f55<\/strong><\/h2>\n<p><p>\u5728Windows\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u78c1\u76d8\u901a\u5e38\u4ee5\u5b57\u6bcd\u547d\u540d\uff0c\u4f8b\u5982C\u76d8\u3001D\u76d8\u7b49\u3002\u8981\u5728Python\u4e2d\u5207\u6362\u5230\u5176\u4ed6\u78c1\u76d8\uff0c\u53ef\u4ee5\u4f7f\u7528<code>os.chdir()<\/code>\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><h2>1. \u4f7f\u7528 os \u6a21\u5757<\/h2>\n<\/p>\n<p><p>Python\u7684<code>os<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u4e0e\u64cd\u4f5c\u7cfb\u7edf\u8fdb\u884c\u4ea4\u4e92\u7684\u529f\u80fd\uff0c\u5176\u4e2d<code>os.chdir()<\/code>\u53ef\u4ee5\u7528\u4e8e\u6539\u53d8\u5f53\u524d\u7684\u5de5\u4f5c\u76ee\u5f55\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<h2><strong>\u5207\u6362\u5230D\u76d8<\/strong><\/h2>\n<p>os.chdir(&#39;D:\\\\&#39;)<\/p>\n<h2><strong>\u67e5\u770b\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55<\/strong><\/h2>\n<p>print(os.getcwd())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u5bfc\u5165\u4e86<code>os<\/code>\u6a21\u5757\uff0c\u7136\u540e\u4f7f\u7528<code>os.chdir(&#39;D:\\\\&#39;)<\/code>\u5c06\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u5207\u6362\u5230D\u76d8\u3002\u6700\u540e\uff0c\u4f7f\u7528<code>os.getcwd()<\/code>\u67e5\u770b\u5f53\u524d\u7684\u5de5\u4f5c\u76ee\u5f55\u3002<\/p>\n<\/p>\n<p><h2>2. \u4f7f\u7528\u7edd\u5bf9\u8def\u5f84<\/h2>\n<\/p>\n<p><p>\u9664\u4e86\u4f7f\u7528<code>os.chdir()<\/code>\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u76f4\u63a5\u5728\u6587\u4ef6\u64cd\u4f5c\u4e2d\u4f7f\u7528\u7edd\u5bf9\u8def\u5f84\u6765\u6307\u5b9a\u6587\u4ef6\u6240\u5728\u7684\u78c1\u76d8\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u6253\u5f00D\u76d8\u4e2d\u7684\u6587\u4ef6<\/p>\n<p>with open(&#39;D:\\\\example.txt&#39;, &#39;r&#39;) as file:<\/p>\n<p>    content = file.read()<\/p>\n<p>    print(content)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u6ca1\u6709\u6539\u53d8\u5de5\u4f5c\u76ee\u5f55\uff0c\u800c\u662f\u76f4\u63a5\u5728\u6587\u4ef6\u8def\u5f84\u4e2d\u6307\u5b9a\u4e86D\u76d8\u3002\u8fd9\u79cd\u65b9\u5f0f\u5728\u5904\u7406\u591a\u4e2a\u78c1\u76d8\u4e0a\u7684\u6587\u4ef6\u65f6\u975e\u5e38\u65b9\u4fbf\u3002<\/p>\n<\/p>\n<h2><strong>\u4e8c\u3001\u4f7f\u7528\u73af\u5883\u53d8\u91cf<\/strong><\/h2>\n<p><p>\u6709\u65f6\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u5728\u7a0b\u5e8f\u4e2d\u52a8\u6001\u5207\u6362\u78c1\u76d8\u3002\u6b64\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u73af\u5883\u53d8\u91cf\u6765\u5b58\u50a8\u78c1\u76d8\u8def\u5f84\uff0c\u7136\u540e\u5728\u7a0b\u5e8f\u4e2d\u6839\u636e\u9700\u8981\u8fdb\u884c\u5207\u6362\u3002<\/p>\n<\/p>\n<p><h2>1. \u8bbe\u7f6e\u73af\u5883\u53d8\u91cf<\/h2>\n<\/p>\n<p><p>\u5728\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\uff0c\u7136\u540e\u5728Python\u4e2d\u8bfb\u53d6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<h2><strong>\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\uff08\u5728\u7cfb\u7edf\u8bbe\u7f6e\u4e2d\u8fdb\u884c\uff09<\/strong><\/h2>\n<h2><strong>os.environ[&#39;DISK_PATH&#39;] = &#39;D:\\\\&#39;<\/strong><\/h2>\n<h2><strong>\u83b7\u53d6\u73af\u5883\u53d8\u91cf<\/strong><\/h2>\n<p>disk_path = os.environ.get(&#39;DISK_PATH&#39;)<\/p>\n<h2><strong>\u5207\u6362\u5230\u6307\u5b9a\u78c1\u76d8<\/strong><\/h2>\n<p>if disk_path:<\/p>\n<p>    os.chdir(disk_path)<\/p>\n<p>    print(f&quot;Changed to {os.getcwd()}&quot;)<\/p>\n<p>else:<\/p>\n<p>    print(&quot;Environment variable &#39;DISK_PATH&#39; not set.&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4f7f\u7528\u8fd9\u79cd\u65b9\u5f0f\u65f6\uff0c\u9996\u5148\u9700\u8981\u5728\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf<code>DISK_PATH<\/code>\uff0c\u7136\u540e\u5728Python\u4e2d\u4f7f\u7528<code>os.environ.get()<\/code>\u83b7\u53d6\u8be5\u53d8\u91cf\u5e76\u5207\u6362\u76ee\u5f55\u3002<\/p>\n<\/p>\n<p><h2>2. \u52a8\u6001\u4fee\u6539\u73af\u5883\u53d8\u91cf<\/h2>\n<\/p>\n<p><p>\u6211\u4eec\u4e5f\u53ef\u4ee5\u5728Python\u4ee3\u7801\u4e2d\u52a8\u6001\u4fee\u6539\u73af\u5883\u53d8\u91cf\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<h2><strong>\u52a8\u6001\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf<\/strong><\/h2>\n<p>os.environ[&#39;DISK_PATH&#39;] = &#39;D:\\\\&#39;<\/p>\n<h2><strong>\u4f7f\u7528\u73af\u5883\u53d8\u91cf\u5207\u6362\u78c1\u76d8<\/strong><\/h2>\n<p>os.chdir(os.environ[&#39;DISK_PATH&#39;])<\/p>\n<p>print(f&quot;Changed to {os.getcwd()}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u5f0f\u9002\u7528\u4e8e\u9700\u8981\u6839\u636e\u7a0b\u5e8f\u903b\u8f91\u52a8\u6001\u4fee\u6539\u78c1\u76d8\u8def\u5f84\u7684\u60c5\u51b5\u3002<\/p>\n<\/p>\n<h2><strong>\u4e09\u3001\u4f7f\u7528 pathlib \u6a21\u5757<\/strong><\/h2>\n<p><p>Python 3.4\u5f15\u5165\u4e86<code>pathlib<\/code>\u6a21\u5757\uff0c\u5b83\u63d0\u4f9b\u4e86\u9762\u5411\u5bf9\u8c61\u7684\u6587\u4ef6\u7cfb\u7edf\u8def\u5f84\u64cd\u4f5c\u63a5\u53e3\u3002<\/p>\n<\/p>\n<p><h2>1. \u521b\u5efa Path \u5bf9\u8c61<\/h2>\n<\/p>\n<p><p><code>pathlib.Path<\/code>\u5bf9\u8c61\u53ef\u4ee5\u8868\u793a\u6587\u4ef6\u6216\u76ee\u5f55\u8def\u5f84\uff0c\u65e0\u8bba\u662f\u76f8\u5bf9\u8def\u5f84\u8fd8\u662f\u7edd\u5bf9\u8def\u5f84\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from pathlib import Path<\/p>\n<h2><strong>\u521b\u5efaPath\u5bf9\u8c61<\/strong><\/h2>\n<p>d_drive = Path(&#39;D:\/&#39;)<\/p>\n<h2><strong>\u67e5\u770bPath\u5bf9\u8c61<\/strong><\/h2>\n<p>print(d_drive)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u8868\u793aD\u76d8\u7684<code>Path<\/code>\u5bf9\u8c61\u3002<\/p>\n<\/p>\n<p><h2>2. \u4f7f\u7528 Path \u5bf9\u8c61\u8fdb\u884c\u64cd\u4f5c<\/h2>\n<\/p>\n<p><p><code>Path<\/code>\u5bf9\u8c61\u63d0\u4f9b\u4e86\u8bb8\u591a\u4fbf\u6377\u7684\u65b9\u6cd5\u7528\u4e8e\u6587\u4ef6\u548c\u76ee\u5f55\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from pathlib import Path<\/p>\n<h2><strong>\u521b\u5efaPath\u5bf9\u8c61\u6307\u5411D\u76d8<\/strong><\/h2>\n<p>d_drive = Path(&#39;D:\/&#39;)<\/p>\n<h2><strong>\u5217\u51faD\u76d8\u4e2d\u7684\u6240\u6709\u6587\u4ef6\u548c\u76ee\u5f55<\/strong><\/h2>\n<p>for item in d_drive.iterdir():<\/p>\n<p>    print(item)<\/p>\n<h2><strong>\u68c0\u67e5\u67d0\u4e2a\u6587\u4ef6\u662f\u5426\u5b58\u5728<\/strong><\/h2>\n<p>file_path = d_drive \/ &#39;example.txt&#39;<\/p>\n<p>print(file_path.exists())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7<code>pathlib<\/code>\uff0c\u6211\u4eec\u53ef\u4ee5\u66f4\u81ea\u7136\u5730\u5904\u7406\u8def\u5f84\u64cd\u4f5c\uff0c\u800c\u65e0\u9700\u9891\u7e41\u4f7f\u7528\u5b57\u7b26\u4e32\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<h2><strong>\u56db\u3001\u5e94\u7528\u573a\u666f\u548c\u6ce8\u610f\u4e8b\u9879<\/strong><\/h2>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u5207\u6362\u78c1\u76d8\u7684\u64cd\u4f5c\u5e38\u7528\u4e8e\u4ee5\u4e0b\u573a\u666f\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u6587\u4ef6\u5907\u4efd\u548c\u6062\u590d<\/strong>\uff1a\u5728\u4e0d\u540c\u78c1\u76d8\u4e4b\u95f4\u8fdb\u884c\u6587\u4ef6\u5907\u4efd\u548c\u6062\u590d\u64cd\u4f5c\u3002<\/li>\n<li><strong>\u591a\u78c1\u76d8\u6570\u636e\u5904\u7406<\/strong>\uff1a\u5728\u591a\u78c1\u76d8\u73af\u5883\u4e2d\u5904\u7406\u548c\u5206\u6790\u6570\u636e\u3002<\/li>\n<li><strong>\u7cfb\u7edf\u7ef4\u62a4\u548c\u7ba1\u7406<\/strong>\uff1a\u5728\u4e0d\u540c\u78c1\u76d8\u95f4\u5207\u6362\u4ee5\u6267\u884c\u7cfb\u7edf\u7ef4\u62a4\u4efb\u52a1\u3002<\/li>\n<\/ul>\n<p><h2>1. \u6ce8\u610f\u4e8b\u9879<\/h2>\n<\/p>\n<p><p>\u5728\u5207\u6362\u78c1\u76d8\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u6743\u9650\u95ee\u9898<\/strong>\uff1a\u786e\u4fdd\u5bf9\u76ee\u6807\u78c1\u76d8\u5177\u6709\u76f8\u5e94\u7684\u8bfb\u5199\u6743\u9650\u3002<\/li>\n<li><strong>\u8def\u5f84\u6b63\u786e\u6027<\/strong>\uff1a\u5728\u4f7f\u7528\u8def\u5f84\u65f6\uff0c\u786e\u4fdd\u8def\u5f84\u683c\u5f0f\u6b63\u786e\uff0c\u5c24\u5176\u662f\u5728Windows\u4e0a\u9700\u8981\u6ce8\u610f\u53cd\u659c\u6760\u7684\u4f7f\u7528\u3002<\/li>\n<li><strong>\u9519\u8bef\u5904\u7406<\/strong>\uff1a\u5728\u5207\u6362\u78c1\u76d8\u548c\u8fdb\u884c\u6587\u4ef6\u64cd\u4f5c\u65f6\uff0c\u505a\u597d\u5f02\u5e38\u5904\u7406\uff0c\u4ee5\u907f\u514d\u7a0b\u5e8f\u5d29\u6e83\u3002<\/li>\n<\/ul>\n<p><h2>2. \u9519\u8bef\u5904\u7406\u793a\u4f8b<\/h2>\n<\/p>\n<p><p>\u5728\u6587\u4ef6\u64cd\u4f5c\u4e2d\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u8def\u5f84\u4e0d\u5b58\u5728\u6216\u6743\u9650\u4e0d\u8db3\u7b49\u95ee\u9898\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5f02\u5e38\u5904\u7406\u6765\u589e\u5f3a\u7a0b\u5e8f\u7684\u5065\u58ee\u6027\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>try:<\/p>\n<p>    # \u5c1d\u8bd5\u5207\u6362\u5230D\u76d8<\/p>\n<p>    os.chdir(&#39;D:\\\\&#39;)<\/p>\n<p>    print(f&quot;Changed to {os.getcwd()}&quot;)<\/p>\n<p>except FileNotFoundError:<\/p>\n<p>    print(&quot;The specified path does not exist.&quot;)<\/p>\n<p>except PermissionError:<\/p>\n<p>    print(&quot;You do not have permission to access this path.&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86<code>try-except<\/code>\u7ed3\u6784\u6765\u6355\u83b7\u5e76\u5904\u7406\u53ef\u80fd\u51fa\u73b0\u7684<code>FileNotFoundError<\/code>\u548c<code>PermissionError<\/code>\u3002<\/p>\n<\/p>\n<h2><strong>\u4e94\u3001\u603b\u7ed3<\/strong><\/h2>\n<p><p>\u5728Python\u4e2d\u5207\u6362\u5230\u5176\u4ed6\u78c1\u76d8\u7684\u64cd\u4f5c\u4e3b\u8981\u4f9d\u8d56\u4e8e<code>os<\/code>\u6a21\u5757\u548c<code>pathlib<\/code>\u6a21\u5757\uff0c\u901a\u8fc7\u6539\u53d8\u5de5\u4f5c\u76ee\u5f55\u3001\u4f7f\u7528\u7edd\u5bf9\u8def\u5f84\u3001\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u7b49\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u540c\u65f6\u6ce8\u610f\u5904\u7406\u53ef\u80fd\u51fa\u73b0\u7684\u9519\u8bef\u548c\u5f02\u5e38\u3002\u638c\u63e1\u8fd9\u4e9b\u6280\u5de7\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u66f4\u9ad8\u6548\u5730\u8fdb\u884c\u591a\u78c1\u76d8\u7684\u6587\u4ef6\u548c\u6570\u636e\u7ba1\u7406\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u8bbf\u95ee\u5176\u4ed6\u78c1\u76d8\u7684\u6587\u4ef6\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684<code>os<\/code>\u6a21\u5757\u6216<code>pathlib<\/code>\u6a21\u5757\u6765\u8bbf\u95ee\u5176\u4ed6\u78c1\u76d8\u4e0a\u7684\u6587\u4ef6\u3002\u9996\u5148\uff0c\u60a8\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u6b63\u786e\u5b89\u88c5\u4e86Python\u73af\u5883\u3002\u63a5\u4e0b\u6765\uff0c\u4f7f\u7528<code>os.chdir(&#39;D:\\\\&#39;)<\/code>\uff08\u5047\u8bbeD\u76d8\u662f\u60a8\u60f3\u8bbf\u95ee\u7684\u78c1\u76d8\uff09\u6765\u66f4\u6539\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u3002\u60a8\u4e5f\u53ef\u4ee5\u901a\u8fc7\u63d0\u4f9b\u5b8c\u6574\u8def\u5f84\u6765\u76f4\u63a5\u8bbf\u95ee\u6587\u4ef6\uff0c\u4f8b\u5982<code>open(&#39;D:\\\\example.txt&#39;, &#39;r&#39;)<\/code>\u6765\u8bfb\u53d6\u6587\u4ef6\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u521b\u5efa\u548c\u5207\u6362\u5230\u65b0\u7684\u78c1\u76d8\u76ee\u5f55\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<code>os.makedirs()<\/code>\u51fd\u6570\u521b\u5efa\u65b0\u76ee\u5f55\u3002\u5982\u679c\u60a8\u5e0c\u671b\u5207\u6362\u5230\u65b0\u521b\u5efa\u7684\u76ee\u5f55\uff0c\u53ef\u4ee5\u4f7f\u7528<code>os.chdir()<\/code>\u51fd\u6570\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u8fd0\u884c<code>os.makedirs(&#39;D:\\\\new_folder&#39;)<\/code>\u6765\u521b\u5efa\u65b0\u6587\u4ef6\u5939\uff0c\u63a5\u7740\u4f7f\u7528<code>os.chdir(&#39;D:\\\\new_folder&#39;)<\/code>\u5c06\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u66f4\u6539\u4e3a\u65b0\u521b\u5efa\u7684\u6587\u4ef6\u5939\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u68c0\u67e5\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\uff1f<\/strong><br \/>\u60a8\u53ef\u4ee5\u4f7f\u7528<code>os.getcwd()<\/code>\u51fd\u6570\u6765\u83b7\u53d6\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u7684\u8def\u5f84\u3002\u8fd9\u5728\u5207\u6362\u5230\u5176\u4ed6\u78c1\u76d8\u540e\u5c24\u4e3a\u91cd\u8981\uff0c\u4ee5\u786e\u4fdd\u60a8\u7684\u64cd\u4f5c\u662f\u5728\u6b63\u786e\u7684\u76ee\u5f55\u4e2d\u8fdb\u884c\u7684\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u8fd0\u884c\u4ee5\u4e0b\u4ee3\u7801\uff1a  <\/p>\n<pre><code class=\"language-python\">import os\nprint(os.getcwd())\n<\/code><\/pre>\n<p>\u8fd9\u6837\u53ef\u4ee5\u5e2e\u52a9\u60a8\u786e\u8ba4\u5f53\u524d\u64cd\u4f5c\u7684\u78c1\u76d8\u548c\u76ee\u5f55\u4f4d\u7f6e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u5207\u6362\u5230\u5176\u4ed6\u78c1\u76d8\u53ef\u4ee5\u901a\u8fc7\u6539\u53d8\u5de5\u4f5c\u76ee\u5f55\u3001\u4f7f\u7528\u7edd\u5bf9\u8def\u5f84\u3001\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u7b49\u65b9\u5f0f\u5b9e\u73b0\u3002\u5176\u4e2d\uff0c\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f [&hellip;]","protected":false},"author":3,"featured_media":1004840,"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\/1004832"}],"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=1004832"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1004832\/revisions"}],"predecessor-version":[{"id":1004841,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1004832\/revisions\/1004841"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1004840"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1004832"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1004832"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1004832"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}