在Python中,你可以使用os
模块的chdir()
函数来更改当前工作目录
import os
# 使用绝对路径更改当前工作目录
abs_path = "/path/to/your/directory"
os.chdir(abs_path)
# 打印当前工作目录以确认更改
print("Current working directory:", os.getcwd())
在这个例子中,将/path/to/your/directory
替换为你想要设置为当前工作目录的绝对路径。os.chdir()
函数会更改当前工作目录,然后os.getcwd()
函数会返回当前工作目录的路径。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:python中cd命令怎么处理相对路径