I have the following code:
f = open("test.tsv", 'wt')
try:
writer = csv.writer(f, delimiter='\t')
for x in range(0, len(ordered)):
writer.writerow((ordered[x][0],"\t", ordered[x][1]))
finally:
f.close()
I need the TSV file to have the ordered[x][0] separated by two tabs with ordered[x][1] the "\t" adds space, but its not a tab and the parentheses are shown on the output.
Thank You!
You could replace the
"\t"
by""
to obtain what you want:Indeed, the empty string in the middle will then be surrounded by a tab on both sides, effectively putting two tabs between
ordered[x][0]
andordered[x][1]
.However, a more natural code doing exactly the same thing would be:
where I:
with
statement (explained here) instead of thetry ... finally
constructt
mode in theopen
function (t
is the default behavior)ordered
usingfor ... in
instead of using an indexjoin
instead of a csv writer: those are suited in cases where the delimiter is a single character