思路:通过获取当前项目下的任意文件位置,并通过传入的项目文件,截取并重新拼接项目的绝对路径
def get_project_data(project_name):
"""
:param project_name: 项目名称
:return:
"""
path_list=os.getcwd().split("\\")
new_path="\\".join(path_list[:path_list.index(project_name)+1])
return new_path
# 假如项目名称为test_demo,
#当前脚本的位置为:D:user\test_demo\test01\test.py
#那么运行脚本,会获取到项目的觉得路径,也就是D:test_demo
get_project_data("test_demo") # 输出D:test_demo