Linux 拨号vps windows公众号手机端

python中如何引入文件路径

lewis 6年前 (2019-03-19) 阅读数 10 #程序编程
文章标签 python

在python中引入文件路径的方法:1.使用os.path.abspath(_ _ file_ _)方法引入文件的绝对路径;2.使用os.path.abspath(sys.argv[0])方法引入文件的绝对路径;3.使用approot模块引入项目所在的绝对路径;

具体方法如下:

1.使用os.path.abspath(_ _ file_ _)方法引入文件的绝对路径

dirname, filename = os.path.split(os.path.abspath( _ _ file_ _))

os.path.realpath(_ _ file_ _)

2.使用os.path.abspath(sys.argv[0])方法引入文件的绝对路径

dirname, filename = os.path.split(os.path.abspath(sys.argv[0]))

os.path.realpath(sys.argv[0])

3.使用approot模块引入项目所在的绝对路径

import approot

print(approot.get_root()+'/FILE/file1.txt')

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门