原文链接:https://blog.csdn.net/Fighting_Yaya/article/details/80275304
‘’ : 当前同级目录
‘/’ :根目录
‘./’ :当前同级目录
‘…/’ :上级目录
示例代码如下:
f = open("aaa.txt","w") #当前目录
f.write("在哪啊")
f.close()f = open("/foo.txt","w") #根目录下
f.write("Python是一个非常好的语言。\n是的,的确非常好!\n")
f.close()f = open("/foo.txt","r")
message = f.readlines()
print(message) #返回一个列表
str = f.read()
print(str) #返回文档的格式f = open("./test.txt","w") #当前目录
f.write("在哪啊?\n")
f.write("是当前目录!")
f.close()f = open("../test.txt","w") #上级目录
f.write("在哪啊?\n")
f.write("是上级目录!")
f.close()