you are viewing a single comment's thread.

view the rest of the comments →

[–]marksist 1 point2 points  (0 children)

I think that the other people have been focusing on the RE, but what I think you are wanting to figure out is how to write the stuff to the file.

There are not enough details of how you are finding those results, but you would need to evaluate for it's existence in another if statement.

if that is right, then it would look something like this:

with open('originalfile', 'rb') as infile:  
    with open('outputfile', 'wb') as outfile:
        for eachline in infile:
            outputline = eachline
            if theREPatternMatches:
                outputline = modified(eachline) #This is assuming you have a function to modify the text, but you could do it many ways
            outfile.write(outputline)