如把test.txt文件的 所有 AAA 字符串 替換成 aaaaa
1 with open('test.txt','+r') as f: 2 t = f.read() 3 t = t.replace('AAA', 'aaaaaa') 4 #讀寫偏移位置移到最開始處 5 f.seek(0, 0) 6 f.write(t)
如把test.txt文件的 所有 AAA 字符串 替換成 aaaaa
1 with open('test.txt','+r') as f: 2 t = f.read() 3 t = t.replace('AAA', 'aaaaaa') 4 #讀寫偏移位置移到最開始處 5 f.seek(0, 0) 6 f.write(t)
本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。