file text replacement | Sololearn: Learn to code for FREE!

0

file text replacement

is it possible to access a .txt file and replace all "t" with "a" with open('file.txt', 'r') as f: with open('file.txt', 'w') as w: for t in f.read(): if "t" in t: w.write("a")

11/27/2021 11:59:21 PM

Tomoe

1 Answer

New Answer

+1

- read the text - change the text (e.g. using .replace()) - save the text https://www.w3schools.com/python/ref_string_replace.asp