Posted on 9th September 2024|20 views
How to save a list as a .CSV file with python with new lines?
I want to save a list in a .CSV file assume i have a list like this
[‘welcome’, ‘to’, ‘mindmajix’]
But I want to save it like this
welcome
to
mindmajix
I tried this
afile = open('/Users/user/Projects/list.csv', 'wb')
wr = csv.writer(afile, quoting=csv.QUOTE_ALL,'\n')
wr.writerow(pos_score)
Posted on 9th September 2024| views
If you are willing to print the words in the different lines then just set the delimiter to \n just like this
s = ['welcome','to','mindmajix']
import csv with open("out.csv","w") as f:
wr = csv.writer(f,delimiter="\n")
wr.writerow(s)
Output:
welcome
to
mindmajix