os.path.dirname(__ file__)返回空
发布于 2021-01-29 19:33:39
我想获取执行.py文件的当前目录的路径。
例如,一个D:\test.py
带有代码的简单文件:
import os
print os.getcwd()
print os.path.basename(__file__)
print os.path.abspath(__file__)
print os.path.dirname(__file__)
输出奇怪的是:
D:\
test.py
D:\test.py
EMPTY
我期待从getcwd()
和获得相同的结果path.dirname()
。
给定os.path.abspath = os.path.dirname + os.path.basename
,为什么
os.path.dirname(__file__)
返回空?
关注者
0
被浏览
74
1 个回答