python获取工程根目录_【Python】获取当前项目根路径/目录
"""
-*- coding:utf-8 -*-
@Time :2020/9/23 18:16
@Author :Jarvis
@File :jar_project_util.py
@Version:1.0
"""
import os
class JarProjectUtil:
@staticmethod
def project_root_path(project_name=None):
"""
獲取當前項目根路徑
:param project_name:
:return: 根路徑
"""
PROJECT_NAME = 'AutoFrame' if project_name is None else project_name
project_path = os.path.abspath(os.path.dirname(__file__))
root_path = project_path[:project_path.find("{}\\".format(PROJECT_NAME)) + len("{}\\".format(PROJECT_NAME))]
print('當前項目名稱:{}\r\n當前項目根路徑:{}'.format(PROJECT_NAME, root_path))
return root_path
if __name__ == '__main__':
JarProjectUtil.project_root_path()
標簽:__,name,Python,路徑,project,path,root,目錄,NAME
來源: https://www.cnblogs.com/danhuai/p/13720419.html
總結
以上是生活随笔為你收集整理的python获取工程根目录_【Python】获取当前项目根路径/目录的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python sslerror_pyth
- 下一篇: office2010 启动man_Off