您需要使用以下命令将文件对象的索引重置为第一个位置
seek():
with open("outfile1.txt", 'r+') as f: f.write("foobar") f.flush() # "reset" fd to the beginning of the file f.seek(0) print("File contents:", f.read())这将使文件可供读取。

您需要使用以下命令将文件对象的索引重置为第一个位置
seek():
with open("outfile1.txt", 'r+') as f: f.write("foobar") f.flush() # "reset" fd to the beginning of the file f.seek(0) print("File contents:", f.read())这将使文件可供读取。