Skip to content

Instantly share code, notes, and snippets.

View panyanyany's full-sized avatar

写代码的安徒生 panyanyany

View GitHub Profile
@tobywf
tobywf / unicode-csv-excel-legacy-python.py
Created August 19, 2017 10:40
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])