在Python中,你可以使用os
模块的chdir()
函数来改变当前工作目录
import os
# 切换到指定目录
new_directory = "/path/to/your/target/directory"
os.chdir(new_directory)
# 获取当前工作目录
current_directory = os.getcwd()
print("当前工作目录:", current_directory)
请将/path/to/your/target/directory
替换为你想要切换到的目录路径。这段代码将在不同的操作系统上正常工作,因为它使用了跨平台的os.chdir()
和os.getcwd()
函数。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:Windows系统通用定时关机命令