Skip to content

Instantly share code, notes, and snippets.

@rafaelhenrique
Created July 5, 2018 12:12
Show Gist options
  • Save rafaelhenrique/93883a33de10742106b32bff4dbc0576 to your computer and use it in GitHub Desktop.
Save rafaelhenrique/93883a33de10742106b32bff4dbc0576 to your computer and use it in GitHub Desktop.
Write csv file
import csv
result = [{'field1': 'teste', 'field2': 'teste'}, {'field1': 'teste1', 'field2': 'teste1'}]
with open('file.csv', 'w', encoding='utf-8') as csvfile:
fieldnames = ['field1', 'field2']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for row in result:
writer.writerow(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment