with open("foo.txt", "a") as f:
f.write("new line\n")
如果你想preprend你拥有的东西从文件中读取:
with open("foo.txt", "r+") as f:
old = f.read() # read everything in the file
f.seek(0) # rewind
f.write("new line\n" + old) # write the new line before
本文由免费oa系统78oa原创,转载请注明出处。