Search and replace a specific word in a file object.

Miki Tebeka miki.tebeka at zoran.com
Mon Jan 12 09:30:11 CET 2004


Hello,

Use the fileinput module:
from fileinput import input

def replace(filename, old, new):
    for line in input(filename, inplace=1):
        print line.replace(old, new)

HTH.
Miki



More information about the Python-list mailing list