Note that there are some explanatory texts on larger screens.

plurals
  1. POpython unicode csv export using pyramid
    text
    copied!<p>I'm trying to export mongodb that has non ascii characters into csv format. Right now, I'm dabbling with pyramid and using pyramid.response. </p> <pre><code>from pyramid.response import Response from mycart.Member import Member @view_config(context="mycart:resources.Member", name='', request_method="POST", permission = 'admin') def member_export( context, request): filename = 'member-'+time.strftime("%Y%m%d%H%M%S")+".csv" download_path = os.getcwd() + '/MyCart/mycart/static/downloads/'+filename member = Members(request) my_list = [['First Name,Last Name']] record = member.get_all_member( ) for r in record: mystr = [ r['fname'], r['lname']] my_list.append(mystr) with open(download_path, 'wb') as f: fileWriter = csv.writer(f, delimiter=',',quotechar='|', quoting=csv.QUOTE_MINIMAL) for l in my_list: print(l) fileWriter.writerow(l) size = os.path.getsize(download_path) response = Response(content_type='application/force-download', content_disposition='attachment; filename=' + filename) response.app_iter = open(download_path , 'rb') response.content_length = size return response </code></pre> <p>In mongoDB, first name is showing <code>王</code>, when I'm using print, it too is showing <code>王</code>. However, when I used excel to open it up, it shows random stuff - ç¾… </p> <p>However, when I tried to view it in shell</p> <pre><code>$ more member-20130227141550.csv </code></pre> <p>It managed to display the non ascii character correctly.</p> <p>How should I rectify this problem?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload