Hi! I got this simple but effective piece of code. It picks certain wanted pieces of data from a textfile based on database records and puts all of them them in a new textfile in certain order. I was wondering, could it be possible to make it otherwise in case that there's much more rows in that textfile and/or there's much more bits of data to collect?
data = open('data.txt','r') f1 = data.readlines() data.close() f2 = open('data.txt','r') i=0 f3 = [] while i < len(f1): a=f2.readline() b=f2.readline() c=f2.readline() data2 = ( a[1:38].strip()+';'+ a[54:88].strip()+';'+ b[77:96].strip()+';'+ b[1:16].strip()+';'+ c[23:33].strip()+';'+ c[123:133].strip()+';' ) wanted = (data2) f3.append(wanted + "\n") i += 3 f4 = open('wanted.txt', 'w') f4.write(''.join(f3)) f2.close() f4.close() Thanks! OV
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor