如何在web2py中生成的CSV报告上强制执行UTF8编码?
答案 0 :(得分:2)
将str.encode
功能与csv模块一起使用,有一个完整的示例可以显示in the Python documentation(或在您的问题的评论中给出的链接)。快速举例:
row = ["one", "two", "three"]
import csv
with open("report.csv", "wb") as f:
writer = csv.writer(f)
writer.writerow([s.encode("utf-8") for s in row])