获取当前文件夹路径及父级目录:
import os current_dir = os.path.abspath(os.path.dirname(__file__)) print(current_dir) #F:\project\pritice current_dir1 = os.path.dirname(__file__) print(current_dir1) #F:/project/pritice parent_path = os.path.dirname(current_dir1) print(parent_path) #F:/project parent_path1 = os.path.dirname(parent_path) print(parent_path1) #F:/ parent_path2 = os.path.dirname(current_dir) print(parent_path2) #F:\project
原文地址:https://www.cnblogs.com/xiaodai0/p/10046470.html
时间: 2024-10-12 02:46:44