Python 设置工作路径:详细指南
要设置 Python 的工作路径,可以使用以下代码:
import os
os.chdir('/path/to/directory')
其中,/path/to/directory 是你想要设置为工作路径的目录。使用 os.chdir() 函数将当前工作路径更改为指定的目录。
你也可以在启动 Python 解释器时使用 -c 参数来设置工作路径,例如:
python -c 'import os; os.chdir('/path/to/directory')'
这将在启动解释器时自动将工作路径更改为指定目录。
原文地址: https://www.cveoy.top/t/topic/m5L4 著作权归作者所有。请勿转载和采集!