我想获取当前目录的路径,在该目录下执行.py文件.
例如,一个D:\test.py包含代码的简单文件:
import os
print os.getcwd()
print os.path.basename(__file__)
print os.path.abspath(__file__)
print os.path.dirname(__file__)
Run Code Online (Sandbox Code Playgroud)
输出结果是奇怪的:
D:\
test.py
D:\test.py
EMPTY
Run Code Online (Sandbox Code Playgroud)
我期待从相同的结果getcwd()和path.dirname().
鉴于os.path.abspath = os.path.dirname + os.path.basename,为什么
os.path.dirname(__file__)
Run Code Online (Sandbox Code Playgroud)
返回空?
python ×1