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:\Users\Administrator\AppData\Local\Programs\Python\Python36\python.exe D:/可以删的/untitled/5.py
D:/可以删的
D:/可以删的/untitled
D:/可以删的

 

posted @ 2020-04-01 10:19  反着来就对了  阅读(390)  评论(0)    收藏  举报