import codecs
import csv
# ファイルの拡張子は.csv
csv_filename = '/tmp/hoge.csv'
# 先頭にBOMを記載
with open(csv_filename, 'wb') as f:
f.write(codecs.BOM_UTF16_LE)
# utf-16-leで追加書き込み。フォーマットはTSV
with codecs.open(csv_filename, 'ab', encoding='utf-16-le', errors='replace') as f:
tsv = csv.writer(f, delimiter="\t")
tsv.writerows([
['Excelで', '正しく', '開ける'],
['csvを', 'pythonで', '作る'],
])
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme