Python 设定工作目录

import os

# 获取当前工作目录
current_dir = os.getcwd()
print(f"当前工作目录: {current_dir}")

# 更改当前工作目录到指定路径
new_dir = "/path/to/your/directory"
os.chdir(new_dir)

# 验证是否已经切换到新目录
new_current_dir = os.getcwd()
print(f"新的当前工作目录: {new_current_dir}")

 

posted @ 2024-01-20 16:22  zwnsyw  阅读(119)  评论(0编辑  收藏  举报