0

I am exporting my data from a list of lists.

when I run the following code

with open('out5.txt','w') as f :
    f.write ('\t'.join(z[0][0]))
    for i in rows:
        f.write ('\t'.join(i))

everything is in the same line but I want a file like this

id    name  Trans

ENS001 EGSB  TTP

EN02   EHGT  GFT
3
  • Is this the same as your earlier question? Commented Dec 30, 2014 at 7:12
  • no. do you have any answer? Commented Dec 30, 2014 at 7:14
  • Sure looks like it to me: you've just replaced ' ' with '\t', and changed the name of the output file. What am I missing? Commented Dec 30, 2014 at 7:16

2 Answers 2

1

You should add a newline characters \n

 f.write('\t'.join(i) + '\n')

I would do it like this :

from __future__ import print_function
with open('out5.txt','w') as f :
    print(*z[0][0], sep="\t", file=f, end="\n")
    for i in rows:
       print(*i, sep="\t", file=f, end="\n")
Sign up to request clarification or add additional context in comments.

Comments

0

You seem to be missing a newline after each print to file. You should try this

with open('out5.txt','w') as f :
    f.write ('\t'.join(z[0][0]))
    f.write ('\n')
    for i in rows:
        f.write ('\t'.join(i))
        f.write ('\n')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.