我有一個 .txt 文件,其內容是:This is an example file.These are its contents.This is line 3.如果我打開文件,移到開頭,然后像這樣寫一些文本......f = open(r'C:\Users\piano\Documents\sample.txt', 'r+')f.seek(0, 0)f.write('Now I am adding text.\n')我期待的是文件讀?。篘ow I am adding text.This is an example file.These are its contents.This is line 3....但它改為:Now I am adding text..These are its contents.This is line 3.那么為什么有些文本被替換而不是我正在寫的文本被簡單地添加到開頭?我怎樣才能解決這個問題?
添加回答
舉報
0/150
提交
取消