从python找到一个文件的绝对路径 [英] finding out absolute path to a file from python
本文介绍了从python找到一个文件的绝对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谢谢。 b $ b
解决方案
答案是使用:
__file__
它返回一个相对路径。
os.path.abspath(__ file__)
可用于获取完整路径。
if I have a file test.py that resides in some directory, how can I find out from test.py what directory it is in? os.path.curdir will give the current directory but not the directory where the file lives. If I invoke test.py from some directory "foo", os.curdir will return foo but not the path of test.py.
thanks.
解决方案
the answer is to use:
__file__
which returns a relative path.
os.path.abspath(__file__)
can be used to get the full path.
这篇关于从python找到一个文件的绝对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文