Program 3: Remove all the lines that contain the character `a’ in a file and write it to another file

Clear Doubts with Computer Tutor
In case you’re facing problems in understanding concepts, writing programs, solving questions, want to learn fun facts | tips | tricks or absolutely anything around computer science, feel free to join CTs learner-teacher community:

#to make sure the file is empty
open("test_res.txt", "w").close()
# make a file object in read mode
with open("test.txt" , "r") as test_file: 
data = test_file.readline()

        if(data.find("a") == -1):
          # make a file object in write mode  
          with open("test_res.txt" , "a")as test_file2: 
        data = test_file.readline()

You cannot copy content of this page