Saturday, January 2, 2016

Python File handling

Python scripting:  Search and replace a string in file.

def Main():
    with open("E:\Softwares\Sample.txt") as f:
        for x, line in enumerate(f):
            if "Valli" in line:
                print line.replace("Valli", "Nayagam", -1),


if __name__ == "__main__":
    Main()

No comments:

Post a Comment