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:Documents
和d:
)中,则第一和第二将工作,而第三将独立于当前工作目录。