help with search & replace

Bill Blue billblue at cham.com
Thu Dec 12 23:38:16 EST 2002


On 12 Dec 2002 14:17:26 -0800, llchen223 at hotmail.com (Lei Chen) wrote:

>Hello,
>
>This will solve your problem:
>
>
>1 inFile = open("infile.txt","r")
>2 of = open("outfile.txt","w")
>3 for line in inFile.xreadlines():
>4     fs = re.compile(r"(\d+:\d+:\d+)").findall(line)
>5     if fs:
>6         for num in fs:
>7             line = line.replace(num,num[0:6]+"00")
>8         of.write(line)
>9     else:
>10        of.write(line)  # for line where no match is found
>
>
>
>Changes are on line 7 and 8.
>
 thank you very much, this works great.

Bill B.





More information about the Python-list mailing list