Remove all the lines that contain the character a in a file and write it to another file in Python.
Answers
Answer:
infile = file('./oldfile.txt')
newopen = open('./newfile.txt', 'w')
for line in infile :
if 'a' in line:
line = line.replace('.' , '')
else:
newopen.write(line)
file.close()
myfile = open("abc1.txt", "r")
newfile = open("abc2.txt", "w")
line = ""
while line:
line = myfile.readline()
if 'a' not in line:
newfile.write(line)
myfile.close()
newfile.close()
print("Newly created file contains")
print("------------")
newfile = open("abc2.txt","r")
line = ""
while line:
line = newfile.readline()
print(line)
newfile.close()
Explanation:
A file is a few data or facts which remains withinside the PC garage devices.
One can already recognize approximately distinctive forms of document , like their track documents, video documents, textual content documents.
Python offers one smooth approach to control those documents. G
Generally we divide documents into categories like textual content document and binary document.