python中os模块获取路径的几种方式
2020-12-13 13:50
标签:project dir style port div name har join color python中os模块获取路径的几种方式 标签:project dir style port div name har join color 原文地址:https://www.cnblogs.com/angelyan/p/11539886.html一、代码
import os
BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
print(BASE_DIR)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
print(BASE_DIR)
BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
print(BASE_DIR)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
print(BASE_DIR)
#结果
D:\PycharmProjects\RPA
D:\PycharmProjects\RPA
D:\PycharmProjects
D:\PycharmProjects