0

Trying to print some strings as rows into a csv however, it gets printed as a column . Code is:

with open('test.csv','w') as b:
a = csv.writer(b)
a.writerows(strings)
b.close()

Output is

GGKKKTKICDKVSHEEDRISQ   ISEILFHLSTKDSVRTSALST   FDSHRDSWIRKLRLDLGYHHD   HLDVHCFHDNKIPLSIYTCTT

I would need it as rows like:

GGKKKTKICDKVSHEEDRISQ

ISEILFHLSTKDSVRTSALST

1 Answer 1

1

writerows expects a list of lists - each inner list a row. I assume that strings is a list of strings, and thus treated like a single row. To covert it to a list of rows, which is what you want, use:

a.writerows([[x] for x in strings])
Sign up to request clarification or add additional context in comments.

1 Comment

@ Korem : Thanks , It prints the rows now but output is in tabs like G G K K T K I C D K V S H ... I need it as a single string.

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.