首页 > 编程语言 > 详细

python获取文件的绝对路径

时间:2021-01-22 10:03:23      阅读:22      评论:0      收藏:0      [点我收藏+]

python获取文件的绝对路径

import os


def load_file():
    # 获取当前文件路径
    current_path = os.path.abspath(__file__)
    # 获取当前文件的父目录
    father_path = os.path.abspath(os.path.dirname(current_path) + os.path.sep + ".")
    # config.ini文件路径,获取当前目录的父目录的父目录与congig.ini拼接
    config_file_path = os.path.join(os.path.abspath(os.path.dirname(current_path) + os.path.sep + ".."), config.ini)
    print(当前目录: + current_path)
    print(当前父目录: + father_path)
    print(config.ini路径: + config_file_path)


load_file()

 

python获取文件的绝对路径

原文:https://www.cnblogs.com/shierlou-123/p/14311619.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!