Replace string within file contents

后端 未结 8 1753
不知归路
不知归路 2020-12-01 00:28

How can I open a file, Stud.txt, and then replace any occurences of \"A\" with \"Orange\"?

8条回答
  •  一向
    一向 (楼主)
    2020-12-01 01:04

    with open("Stud.txt", "rt") as fin:
        with open("out.txt", "wt") as fout:
            for line in fin:
                fout.write(line.replace('A', 'Orange'))
    

提交回复
热议问题