开发者

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])
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜