1.

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()



Discussion

No Comment Found

Related InterviewSolutions