3 回答
TA贡献1998条经验 获得超6个赞
此处提供的模块看起来像是csv模块的酷炫,简单,直接的替代品,使您可以使用utf-8 csv。
import ucsv as csv
with open('some.csv', 'rb') as f:
reader = csv.reader(f)
for row in reader:
print row
TA贡献2065条经验 获得超14个赞
该文档中已经有Unicode示例的用法,为什么还需要寻找另一个示例或重新发明轮子呢?
import csv
def unicode_csv_reader(unicode_csv_data, dialect=csv.excel, **kwargs):
# csv.py doesn't do Unicode; encode temporarily as UTF-8:
csv_reader = csv.reader(utf_8_encoder(unicode_csv_data),
dialect=dialect, **kwargs)
for row in csv_reader:
# decode UTF-8 back to Unicode, cell by cell:
yield [unicode(cell, 'utf-8') for cell in row]
def utf_8_encoder(unicode_csv_data):
for line in unicode_csv_data:
yield line.encode('utf-8')
添加回答
举报