我在寻找解决办法,但还没有找到我需要的。
脚本路径:/dir/to/Script/Script.py或C:\ dir\Script.py
例外结果:
$ ./script.py
output: /dir/to/script
$ cd .. && ./script/script.py
output: /dir/to/script
操作系统模块里有什么功能吗?
我混合解决方案并写下:
print os.path.abspath(os.path.dirname(__file__))
但是很难看。有更好的办法吗?
Tags:
os.path.realpath将为您提供结果:
相关问题 更多 >
编程相关推荐