How can i add encoding to the python generated CSV file

Posted by user1958218 on Stack Overflow See other posts from Stack Overflow or by user1958218
Published on 2013-06-26T04:06:05Z Indexed on 2013/06/26 4:21 UTC
Read the original article Hit count: 224

Filed under:
|
|

I am following this post

http://stackoverflow.com/a/9016545

and i want to know that how can i do that in Python. I don't know how can i insert BOM data in there

This is my current code

    response = HttpResponse(content_type='text/csv')
    response['Content-Type'] = 'application/octet-stream'
    response['Content-Disposition'] = 'attachment; filename="results.csv"'
    writer = UnicodeWriter(response, quoting=csv.QUOTE_ALL, encoding="utf-8")

I want to convert to utf -16 . BOm data is this but don't know how to insert it From here http://stackoverflow.com/a/4440143

echo "\xEF\xBB\xBF"; // UTF-8 BOM

But i want it for python and utf-16

I tried opening that csv in notepad and insert \xef\xbb\xb in beginning and excel displayed that correctly. But it is also visible before first column.

How can i hide that because user wont like that

© Stack Overflow or respective owner

Related posts about python

Related posts about csv