Skip to content

Instantly share code, notes, and snippets.

@onestarshang
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save onestarshang/6a15e9739dd92675b37a to your computer and use it in GitHub Desktop.

Select an option

Save onestarshang/6a15e9739dd92675b37a to your computer and use it in GitHub Desktop.
#coding:utf-8
import csv
import sys
####write
info = [(1,2,3),
(2,3,4),
(3,4,5),
('test','test2','test3')]
with open('test1.csv','wb') as f:
writer = csv.writer(f)
for item in info:
writer.writerow(item)
###中文编码
info = [('1','2','3'),
('2','3','4'),
('3','4','5'),
(u'汉字'.encode('gb2312'),'test2','test3')]
with codecs.open('test1.csv','wb') as f:
writer = csv.writer(f)
writer.writerow((u'第一列'.encode('gb2312'), u'第二列'.encode('gb2312'), 'third row'))
for item in info:
writer.writerow(item)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment