Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python how to replace a certain string in text

# Read in the file
with open('file.txt', 'r') as file :
  filedata = file.read()

# Replace the target string
filedata = filedata.replace('ram', 'abcd')

# Write the file out again
with open('file.txt', 'w') as file:
  file.write(filedata)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #replace #string #text
ADD COMMENT
Topic
Name
5+5 =