Replace a content in a Text file in python

75 Views Asked by At

From a text file want to replace the content to * for example in a text file, I want to replace all the content after the password:

1

There are 1 best solutions below

0
On

You can use this regex after reading and before writing.

import re
pattern = 'password'
string = file.read()
result = re.split(pattern, string)
newtext=result[0]