在Python中,您可以使用os
模块中的chdir()
函数来更改当前工作目录
import os
# 切换到指定目录
new_directory = "/path/to/your/target/directory"
os.chdir(new_directory)
# 打印当前工作目录以确认更改
print("Current working directory:", os.getcwd())
请确保将/path/to/your/target/directory
替换为您要切换到的实际目录路径。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:python中cd命令能自动切换目录吗