我想要获取执行.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__)
返回空?