I have a large volume of files to change so I need to
automate the search and replace. I'll be replacing
bits of text with other bits of text. This is working
for now but I'd like to know how a real programmer
would do it. The hard coded strings will eventually
come from a list. All sugestions welcome and
appreciated.

    #read all file lines into list and close
    allLines = fh.readlines()
    fh.close()
    
    #use split and join to replace a unique item
    chunk = allLines[0]
    splitChunk = chunk.split('xVAR1x')
    newChunk = 'my shoes fell off'.join(splitChunk)

        #write to a file
    file = open('test.html', 'w')
    for eachLine in newChunk:
        print 'writing  line in text file'
        file.write(eachLine)
    file.close()


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to