def make_csv_output(res, dt):
 import frappe
 from cStringIO import StringIO
 import csv
 f = StringIO()
 writer = csv.writer(f)
 for r in res:
  row = []
  for v in r:
   if isinstance(v, basestring):
    v = v.encode(u'utf-8')
   row.append(v)
  writer.writerow(row)
 f.seek(0)
 frappe.response[u'result'] = unicode(f.read(), u'utf-8')
 frappe.response[u'type'] = u'csv'
 frappe.response[u'doctype'] = dt.replace(u' ', u'')

def make_csv_output ( res , dt ) : import frappe from cStringIO import StringIO import csv f = StringIO ( ) writer = csv . writer ( f ) for r in res : row = [ ] for v in r : if isinstance ( v , basestring ) : v = v . encode ( u'utf-8' ) row . append ( v ) writer . writerow ( row ) f . seek ( 0 ) frappe . response [ u'result' ] = unicode ( f . read ( ) , u'utf-8' ) frappe . response [ u'type' ] = u'csv' frappe . response [ u'doctype' ] = dt . replace ( u' ' , u'' )
send method response as downloadable csv file .