This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
arbitrary_list_of_dictionaries = [{'hello': 'world'}, {'hello': 'you'}] | |
arbitrary_output_path = 'output.csv' | |
# Use the keys from the first dictionary as field names in CSV | |
field_names = [key for key in arbitrary_list_of_dictionaries[0].keys()] | |
# Note: The 'encoding' argument is important. It adds a BOM (byte order mark) | |
# to the beginning of the file. |