Q. Write a program that copies a text file "source.txt" onto "target.txt" barring the lines starting with a "@" sign.
Answer :-
def filter (oldfile, newfile): fin = open(oldfile, "r") fout = open(newfile, 'w') while True: text = fin.readline() if len(text) == 0: break if text [0] = "@": continue fout.write(text) fin.close() fout.close()
Output :-
>>>filter("source.txt", "target.txt")
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )