My csv output is not coming out the way I planned. My code:
first_row = list(ws.rows)[1]
first_row_values = []
first_row_values.append(value1)
first_row_values.append(value2)
first_row_values.append(value3)
first_row_values.extend([cell.value for cell in first_row])
print(first_row_values)
writer = csv.writer(open('output.csv', 'a+'))
writer.writerow([first_row_values])
the output in the file looks like this:
"['value1', 'value2', 'value3', 'valueA', 'valueB', 'valueC', 'valueD', 'valueE', 'valueF', 'valueG', 'valueH', 'valueI', 'valueJ']"
I'm expecting a csv output:
'value1', 'value2', 'value3', 'valueA', 'valueB', 'valueC', 'valueD', 'valueE', 'valueF', 'valueG', 'valueH', 'valueI', 'valueJ'
What am I missing here?
[]around first_row_values in the last row.writer.writerow([first_row_values]).first_row_valuesis already a list, now you made it into a nested list that is the first element of your row, so the whole things gets converted to a string.