下列哪一项可用于打开位于不同位置(d:Documents)的文件(t3.txt)以供阅读?



a)with open(“t3.txt”, “r”) as f:

b)with open(“Documentst3.txt”, “r”) as f:

c)with open(“d:\Documents\t3.txt”, “r”) as f:

d)以上任何一个

有人愿意解释一下如何知道哪一个将允许我打开位于不同位置的文件吗?I tried and c) works.

This:

with open(“t3.txt”, “r”) as f:

with open(“Documentst3.txt”, “r”) as f:

使用相对路径,而

with open(“d:Documentst3.txt”, “r”) as f:

确实使用绝对路径,因此如果您在特定的工作目录(分别为d:Documentsd:)中,则第一和第二将工作,而第三将独立于当前工作目录。

相关内容

最新更新