Replace unknow string varible in file.

namire namire at
Tue Feb 10 15:54:14 EST 2009

Hey .python first time poster here. I'm pretty good with python so
far, but I keep needed a function in my program but not knowing how to
build it. =( Here's the problem:

Imagine a html file full of 100's of these strings all mooshed
together onto many lines;
<!--"@@MARKER@@; id=ITEM"-->ITEM<br>
Where the word 'MARKER' is a constant, it stay the same in each string
and the word 'ITEM' is a random combination of ascii characters of an
unknown length. So for example a:
<!--"@@MARKER@@; id=CATFISH"-->CATFISH<br><h1>Text text text</
h1><!--"@@MARKER@@; id=SPAM"-->SPAM<br> and so on...

What I need to do it replace each instance of the random letter with a
constant and/or delete them. The file is a html file so the stuff
inside of <!-- --> is ok to keep and I need that data to identify
where the strings are in the file (it's full of other stuff too).  I'm
tired making a bruteforcer but with unknown length and 26 letters of
the alphabet I gave up because it would take too long (it was
something like; read file; if '@@MARKER@@; id="'+str(gen_string)+'"--
>"+sr(gen_string)+'<br>' in file then replace with '', but I'm
paraphrasing code and it's not the best solution anyway).

Just as a comparison in the Windows OS this seems easy to do when
managing files, say for the file a-blah-b-blah.tmp where blah is an
unknown you can use: del a-*-b-*.tmp to get rid of that file. But for
python and a string in text file I don't have a clue. @_@ could
someone please help me?

More information about the Python-list mailing list