python 切换工作目录

切换到指定名字的目录,作为init文件,在别的文件中import该文件就可以完成切换目录

# 切换工作目录

import os

current_path = os.getcwd()
print(current_path)

project_name = ‘project‘

current_path = current_path[:current_path.find(project_name) + len(project_name)]
os.chdir(current_path)

print(os.getcwd())

相关推荐