I have several lists of various lengths that I am trying to export to CSV so they can be called up again later when the program is launched again. Everytime I try the following, it only outputs a single line of data to the csv:
export = [solutions, fedata, bbcom, fenxt, ten_99, ten_99links]
with open('test.csv','w') as f:
writer = csv.writer(f)
# writer.writerow([<header row>]) #uncomment this and put header, if you want header row , if not leave it commented.
for x in zip(*export):
writer.writerow(x)
some of the lists currently only have 1 item in them, but I am trying to basically make a CSV be a database for this program as we will be adding more to the lists as it is expanded. Any help is appreciated, I am really banging my head against the wall here.
I tried the pasted code but it only outputs a single line of data
CodePudding user response:
Do you want every item to be on a newline or every list on a newline?
If you want an empty line between the prints then you can remove the newline=''
Try this:
with open('test.csv', 'w', newline='') as f:
writer = csv.writer(f)
writer.writerows(export)