Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Help with new line character

Tags:

python

I read in a text file that is tab delimited, i then have a list for each line, i then index out the first entry of each list, i then write this to a file. code below:

import csv
z = csv.reader(open('output.blast'), delimiter='\t')
k = open('output.fasta', 'w')
for row in z:
    print row[1:12]
    for i in row[1:12]:
        k.write(i+'\t')

When writing to the file it writes it as one long line, i would like a new line to be started after the 11th (last) entry in each list. But i cannot figure out where to put the new line charater

like image 506
Liam Avatar asked Feb 27 '23 17:02

Liam


1 Answers

It sounds like you just want it after each row, so put it at the end of the for loop that iterates over the rows:

for row in z:
    print row[1:12]
    for i in row[1:12]:
        k.write(i+'\t')
    k.write('\n')
like image 192
Michael Mrozek Avatar answered Mar 08 '23 09:03

Michael Mrozek