I have a list:
[cat, dog, mouse] and I wish for all the list items to be headers in a csv file like this:
cat,dog,mouse data,data,data date,data,data I have the following code to open a file, but I am not sure how to assign the animals to the headers:
with open(fname, 'w') as my_csv: my_csv.write(#cat,dog,mouse needs to go in here) csv_writer = csv.writer(my_csv, delimiter=',') I don't want to explicitly write cat,dog,mouse as these animals can change due to user input choosing the animals further up the code.
jointhe elements with a comma and write this as the first line:','.join(list)by the way using variable namelistis poor form you should use something else likeheader_namesor something