Last active
August 29, 2015 14:02
-
-
Save onestarshang/6a15e9739dd92675b37a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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