2017-11-25 167 views
2

我试着用:在python中,我如何获得“。”的完整路径名?

dir = os.path.dirname(".") 

而且回是空的。

+0

的[“查找当前目录和文件的目录可能的复制“](https://stackoverflow.com/questions/5137497/find-current-directory-and-files-d irectory) –

+1

[Find current directory and file's directory](https://stackoverflow.com/questions/5137497/find-current-directory-and-files-directory) – klutt

+2

'dirname'甚至没有看到文件系统;它完全是一个文件路径上的字符串操作,在最后一个'/'之后(大致)丢弃了该部分。 – chepner

回答

3

使用abspath

dir = os.path.abspath('.') 

或当前工作目录

dir = os.path.getcwd() 
相关问题