How do I enforce a UTF8 encoding on a generated CSV report?
How do I enforce a UTF8 encoding on a generated CSV repo开发者_JAVA百科rt in web2py?
Use the str.encode
function together with the csv module, there is a complete example that will show you that in the Python documentation (or in the link given in comment to your question). Quick example:
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])
精彩评论