os.path.dirname(__file__) 返回当前文件的绝对路径
Posted lexus168
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了os.path.dirname(__file__) 返回当前文件的绝对路径相关的知识,希望对你有一定的参考价值。
import os print(os.path.dirname(os.path.dirname(__file__))) print(os.path.dirname(__file__)) print(os.path.dirname("D:/可以删的/untitled"))
结果
C:UsersAdministratorAppDataLocalProgramsPythonPython36python.exe D:/可以删的/untitled/5.py D:/可以删的 D:/可以删的/untitled D:/可以删的
以上是关于os.path.dirname(__file__) 返回当前文件的绝对路径的主要内容,如果未能解决你的问题,请参考以下文章