import csv
toCSV = [{'name':'bob','age':25,'weight':200},
{'name':'jim','age':31,'weight':180}]
header=['name','age','weight']
try:
with open('output'+str(date.today())+'.csv',mode='w',encoding='utf8',newline='') as output_to_csv:
dict_csv_writer = csv.DictWriter(output_to_csv, fieldnames=header,dialect='excel')
dict_csv_writer.writeheader()
dict_csv_writer.writerows(toCSV)
print('\nData exported to csv succesfully and sample data')
except IOError as io:
print('\n',io)