tags:

views:

103

answers:

1

how to enforce encoding of a generated csv report to make it "utf8"

Thanks in advance

+1  A: 

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