如把test.txt文件的 所有 AAA 字元串 替換成 aaaaa 1 with open('test.txt','+r') as f: 2 t = f.read() 3 t = d.replace('AAA', 'aaaaaa') 4 #讀寫偏移位置移到最開始處 5 f.seek(0, 0) 6
如把test.txt文件的 所有 AAA 字元串 替換成 aaaaa
1 with open('test.txt','+r') as f: 2 t = f.read() 3 t = d.replace('AAA', 'aaaaaa') 4 #讀寫偏移位置移到最開始處 5 f.seek(0, 0) 6 f.write(t)