Replace parts of a file?

Gustaf Liljegren gustafl at
Sat Sep 30 22:12:17 CEST 2000

Here's a newbie question. I'm working with a script for replacing the 
header and footer sections of multiple HTML files. I don't think I can use 
SSI here, as I need to change some file paths in these sections too.

For example, the footer (in this case) is everything below the last "<hr>". 
Below that line, different files may look a slightly different. After the 
"<hr>", I want to remove everything and replace it with a standardized 
footer from another file. I came this far:

  file = open(filename, "r+")
  start = string.rfind(file, "<hr>")

I've been looking for a function that return a substring based on a start 
and end value, but hasn't found any. Maybe there's a better way?



More information about the Python-list mailing list