user3351370 user3351370 - 1 year ago 78
Python Question

Write list and value in same row csv

I have several values and severals list with differents length.
I'd like to write them in the same CSV row.

I have these values





As output I'd like a csv file like this :


So far I coded this

resultFile = open("DNA_Movie.csv",'wb')
wr = csv.writer(resultFile, dialect='excel')
wr.writerows([imdb_id, genre, actors])

But the result is like this:


Answer Source

Use writerow and combine each element together into a single list:

wr.writerow([a] + b + [c] + d)

Some of the elements need to be wrapped in brackets to turn them into a list with a single element.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download