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:/可以删的

猜你喜欢

转载自www.cnblogs.com/lexus168/p/12610774.html