Python Replace Word in a File || File Handling || Python
In this we are going to see a basic program to replace word in a file in Python Programming Language.


def replace_word():
    f = open("file.txt", "r")
    lines = f.readlines()
    f.close()
    for line in lines:
        line = line.replace("Coders", "Influencer")
        print(line)

    f = open("file.txt", "w")
    f.write("".join(lines))
    f.close()

replace_word()

# Coded By Dhiraj Shelke


#ENJOY CODING


Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post