Skip to content

Instantly share code, notes, and snippets.

@tobywf
Created August 19, 2017 10:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobywf/5be49947253abf1c0cd56d27568d4ad7 to your computer and use it in GitHub Desktop.
Save tobywf/5be49947253abf1c0cd56d27568d4ad7 to your computer and use it in GitHub Desktop.
Generate a UTF-8 comma separated value (CSV) file that Excel reads reliably (Legacy Python 2, shame)
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from backports import csv
from io import open
with open('test.csv', 'w', encoding='utf-8-sig', newline='') as fp:
writer = csv.writer(fp)
writer.writerow(['Row', 'Emoji'])
for i, emoji in enumerate(['🎅', '🤔', '😎']):
writer.writerow([str(i), emoji])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment