如何在Python中获得绝对文件路径给定一条路径,如"mydir/myfile.txt",如何在Python中找到文件相对于当前工作目录的绝对路径?例如,在Windows上,我最终可能会:"C:/example/cwd/mydir/myfile.txt"
3 回答

FFIVE
TA贡献1797条经验 获得超6个赞
>>> import os>>> os.path.abspath("mydir/myfile.txt")'C:/example/cwd/mydir/myfile.txt'
>>> import os>>> os.path.abspath("C:/example/cwd/mydir/myfile.txt")'C:/example/cwd/mydir/myfile.txt'
添加回答
举报
0/150
提交
取消