给定一个路径,例如"mydir/myfile.txt",如何在Python中找到文件的绝对路径?例如。在Windows上,我可能会得到:"C:/example/cwd/mydir/myfile.txt" 最佳答案 >>>importos>>>os.path.abspath("mydir/myfile.txt")'C:/example/cwd/mydir/myfile.txt'如果它已经是绝对路径也可以:>>>importos>>>os.path.abspath("C:/example/cwd/mydir/myfile.txt")'C