Replace string within file contents

后端 未结 8 1778
不知归路
不知归路 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:10

    #!/usr/bin/python
    
    with open(FileName) as f:
        newText=f.read().replace('A', 'Orange')
    
    with open(FileName, "w") as f:
        f.write(newText)
    

提交回复
热议问题