mercredi 4 novembre 2015

append every 8 lines of a file to a new file conditionally

I have a file with a set of lines in it. Every 8 lines contains a sample that I need to test with an 'if' statement. If the 8 lines is accepted I need it to send that text to an 'accepted file'- 'else' the 8 lines are sent to another 'notaccepted file': for line in range(0,len(outfile),8):#outfile=variable storing file lines if avergm or avergt <30: not_accepted=open("unacceptable.txt", "a") not_accepted.append(outfile[0:7]) else:
accepted=open("accepted_samples.txt", "a") accepted.append(oufile[0:7]) My problem is that with the 'accepted.append(oufile[0:7])' only the first 8 lines are appended to the 'accepted/notaccepted file' and I need this to iterate through all of the 8 line entities in 'outfile' and append them in accordingly. Any help?

Aucun commentaire:

Enregistrer un commentaire