i = 1 # keep track of file number
directory = '/some/directory/'
for i in range(1, 5170): #number of files in directory
filename = directory + 'D' + str(i) + '.txt'
input = open(filename)
output = open('output.txt', 'w')
input.readline() #ignore first line
for g in range(0, 7): #write next seven lines to output.txt
output.write(input.readline())
output.write('\n') #add newline to avoid mess
output.close()
input.close()
i = i + 1
我有这段代码,我正在尝试获取一个文件并将其重写为 output.txt,但是当我想附加下一个文件时,我的代码会覆盖已附加的旧文件。结果当代码完成时,我有这样的东西:
dataA[5169]=26
dataB[5169]=0
dataC[5169]=y
dataD[5169]='something'
dataE[5169]=x
data_date[5169]=2012.06.02
而不是从文件 0 到 5169 的数据。任何提示如何修复它?