How do I enforce a UTF8 encoding on a generated CSV report?

Tags: python web2py
By : Neveen
Source: Stackoverflow.com
Question!

How do I enforce a UTF8 encoding on a generated CSV report in web2py?

By : Neveen


Answers

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])
By : WildSeal


This video can help you solving your question :)
By: admin