toCSV = [{'name': 'bob', 'age': 25, 'weight': 200}, {'name': 'jim', 'age': 
    31, 'weight': 180}]
keys = list(toCSV[0].keys())
with open('people.csv', 'wb') as output_file:
    dict_writer = csv.DictWriter(output_file, keys)
dict_writer.writeheader()
dict_writer.writerows(toCSV)
How do I convert this list of dictionaries to a csv file? [Python]