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
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])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.