I/O

Peter Scott sketerpot at chase3000.com
Tue Dec 17 18:25:20 EST 2002


Tee Bee wrote:
> My first problem at the moment is, that I got a 1 or 2 dozen of HTML-files
> with text-passages that need to be changed or deleted.
> 
> f.e.:
> 
> 1. <b>this is a text-passage</b>    <= Content of the file.
> 
> 2. read every byte
> 
> 3. compare
> 
> 4. delete or change content

That looks like a job for sed or perl. With those you could do 
"s/<b>this is a text-passage</b>/<b>This is what to replace it with/g" 
and just run this sed script on all the files you want. The perl syntax 
is similar.

If you really want to use Python, such as if you have this as part of a 
larger application or want Python's portability, I believe that you 
could go through all your files and use "string.replace(myString, 
'<b>this is a text-passage</b>', '<b>This is what to replace it with')"

Hopefully those should do the trick.

-Peter




More information about the Python-list mailing list