Wildcard for string replacement?!?!

John Roth johnroth at ameritech.net
Tue Mar 11 01:44:21 CET 2003

"Perverted Orc" <perverted_orc at softhome.net> wrote in message
news:b4inu9$8s3$1 at usenet.otenet.gr...
> Hello everyone!
> I 'm working for over a week on this script but I can't make my way
out. The
> whole idea is to replace (better say delete) anything that stands
> the <td> and</td> tag of an html file.
> from string import *
> pname=raw_input("Give path\ :") #The path name where the original file
> and the new to be saved
> fnameo=raw_input("Give file to change :")
> fnamen=raw_input("...Save As :")
> old_file=pname+fnameo #Joining path and file name
> new_file=pname+fnamen #Joining path and file name
> inp=open (old_file,'r')
> outp=open(new_file,'w')
> for line in inp.readlines():
>      nline=replace(line,"?????"," ")
>      outp.write(nline)
> print "1 file changed and saved..."
> inp.close()
> outp.close()
> Can anyone tell me what to fill in the ????? area? I tried any
> combination with "." and "*" but didn't work.
> Please help!!!

Pattern matching isn't going to work for a number of reasons.
An example of code that does *exactly* what you want is embedded
in the Python version of the FIT processor at fit.c2.com.
Look at the "Parse" module. There's a description somwhere on that
Wiki that gives the rationale behind the rather lispish design. It took
me a while to figure it out, but for the purpose of pulling strings out
of tables and rewriteing them, it rocks.

John Roth

More information about the Python-list mailing list