PW Akshay

Generation

generate functionFri, 02 Dec 2022

Remove all the lines that contain the character 'a' in a file and write it to another file

import os def remove_a(): f1 = open('test.txt', 'r') f2 = open('test2.txt', 'w') for line in f1.readlines(): if 'a' not in line: f2.write(line) f1.close() f2.close() remove_a()

Questions about programming?Chat with your personal AI assistant