4259 links
  • Arnaud's links
  • Home
  • RSS Feed
  • Tag cloud
  • Login
search: tag:python tag:replace — newest first
  • python - How to search and replace text in a file? - Stack Overflow

    Sometime you cant use sed :(

    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)

    July 7, 2021 - permalink - https://stackoverflow.com/questions/17140886/how-to-search-and-replace-text-in-a-file
    nomarkdown python replace