在python中,我如何获得“。”的完整路径名?
答
使用abspath
:
dir = os.path.abspath('.')
或当前工作目录
dir = os.path.getcwd()
的[“查找当前目录和文件的目录可能的复制“](https://stackoverflow.com/questions/5137497/find-current-directory-and-files-d irectory) –
[Find current directory and file's directory](https://stackoverflow.com/questions/5137497/find-current-directory-and-files-directory) – klutt
'dirname'甚至没有看到文件系统;它完全是一个文件路径上的字符串操作,在最后一个'/'之后(大致)丢弃了该部分。 – chepner