Sep-26-2017, 01:30 PM
Still not sure what you are looking for, because you are ambiguous in the use of column, but I'll see what I can do.
If we take this code, which uses your 'for' statement:
If we take this code, which uses your 'for' statement:
import csv cellContent = ['Peter', 'Paul', 'Mary', 'Jane'] with open('csv_file.csv', 'w') as new_file: writer = csv.writer(new_file) for cell in cellContent: writer.writerow(cell)you end up with a file content of
Output:P,e,t,e,r
P,a,u,l
M,a,r,y
J,a,n,e
Not what you are looking for I take it, plus you have an extra line between rows. We can avoid the extra lines by adding newline=''
to the open() function, and remove the commas using the split()
function. The code now looks like:import csv cellContent = ['Peter', 'Paul', 'Mary', 'Jane'] with open('csv_file.csv', 'w', newline='') as new_file: writer = csv.writer(new_file) for cell in cellContent: writer.writerow(cell.split(','))and the file looks like
Output:Peter
Paul
Mary
Jane
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition