python CSV写中文

    

 1 def OnDeleteClick(self, event):
 2         import os
 3         dlg = wx.FileDialog(self,message=u"保存文件",
 4                             defaultDir=os.getcwd(),
 5                             defaultFile="",
 6                             wildcard="CSV (*.csv)|*.csv",
 7                             style=wx.SAVE)
 8         import codecs,csv
 9         if dlg.ShowModal() == wx.ID_OK:
10             f = codecs.open(dlg.GetPath(),'w','gb2312')#这里表示把intimate.txt文件从utf-8编码转换为unicode,就可以对其进行unicode读写了
11             writer = csv.writer(f,delimiter=',')
12             writer.writerow([u"列1",u"列2",u"列2",u"列02",u"列2"])
13             writer.writerows(self.__Grid.GetTable().Data)
14             f.close()
15             dlg.Destroy()

 

posted @ 2018-04-18 00:04  aloneOnWorld  阅读(569)  评论(0编辑  收藏  举报