我正在尝试用PyQt4 QTableWidget
创建csv格式的文本文件。我想用UTF-8编码编写文本,因为它包含特殊字符。我使用以下代码:
import codecs
...
myfile = codecs.open(filename, 'w','utf-8')
...
f = result.table.item(i,c).text()
myfile.write(f+";")
它在单元格包含特殊字符之前一直有效。我也尝试过
myfile = open(filename, 'w')
...
f = unicode(result.table.item(i,c).text(), "utf-8")
但它也会在出现特殊字符时停止。我不知道我做错了什么。
发布于 2016-05-21 22:50:43
发布于 2015-07-27 05:19:04
从您的shell运行:
pip2 install unicodecsv
(与原始问题不同)假设您正在使用Python的内置csv
模块,请依次
import csv
into
在您的代码中使用import unicodecsv as csv
。
发布于 2014-03-24 19:07:53
使用这个包,它就能工作:https://github.com/jdunck/python-unicodecsv。
https://stackoverflow.com/questions/18766955
复制相似问题