Replace parts of a file?
Kragen Sitaker
kragen at dnaco.net
Sat Sep 30 21:57:27 EDT 2000
In article <8FBFE4B0Egustaflalgonetse at 194.213.69.152>,
Gustaf Liljegren <gustafl at algonet.se> wrote:
>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 don't think string.rfind will work well on the file object; I think
you'll need to use read() to read the contents of the file into a
string and use string.rfind on that.
>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?
Like this?
>>> mystring = 'this is a test'
>>> mystring
'this is a test'
>>> mystring[5:12]
'is a te'
HTH.
--
<kragen at pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
Perilous to all of us are the devices of an art deeper than we ourselves
possess.
-- Gandalf the Grey [J.R.R. Tolkien, "Lord of the Rings"]
More information about the Python-list
mailing list