Running this code creates file2.txt as expected, but the file is empty. (Note: file1.txt just has the lines of a poem.) Why does this happen? How can I get it to write array a2 to a text file?
import copy
#Open input file, read it into an array, and remove the every other line.
f = open('file1.txt','r')
a1 = f.readlines()
a2 = copy.deepcopy(a1)
f.close
for n in range(len(a1)):
if n%2 == 0:
a2.remove(a1[n])
# Open output file and write array into it.
fo = open('file2.txt','w')
fo.writelines(a2)
fo.close