代码演示了Python基本的文件操作,包括 open,read,write:
# 文件的基本操作,包括open,read,write
with open("test.txt", "wt") as out_file:
out_file.write("该文本会写入到文件中\n看到我了吧!")
# Read a file
with open("test.txt", "rt") as in_file:
text = in_file.read()
print(text)
结果:
该文本会写入到文件中
看到我了吧!
Process finished with exit code 0