Program inefficiency?

hall.jeff at gmail.com hall.jeff at gmail.com
Sat Sep 29 20:32:07 CEST 2007


It think he's saying it should look like this:

# File: masseditor.py

import re
import os
import time

p1= re.compile('(href=|HREF=)+(.*)(#)+(.*)(\w\'\?-<:)+(.*)(">)+')
p2= re.compile('(name=")+(.*)(\w\'\?-<:)+(.*)(">)+')
p100= re.compile('(a name=)+(.*)(-)+(.*)(></a>)+')
q1= r"\1\2\3\4_\6\7"
q2= r"\1\2_\4\5"

def massreplace():
    editfile = open("C:\Program Files\Credit Risk Management\Masseditor
\editfile.txt")
    filestring = editfile.read()
    filelist = filestring.splitlines()

    for i in range(len(filelist)):
        source = open(filelist[i])
        starttext = source.read()

        for i in range (13):
            interimtext = p1.sub(q1, starttext)
            interimtext= p2.sub(q2, interimtext)
            interimtext= p100.sub(q2, interimtext)
        source.close()
        source = open(filelist[i],"w")
        source.write(finaltext)
        source.close()

massreplace()

I'll try that and see how it works...




More information about the Python-list mailing list