Search and replace a specific word in a file object.

Miki Tebeka miki.tebeka at zoran.com
Mon Jan 12 03:30:11 EST 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