title: (Python) Write string to CSV with UTF-8 Encoding
body: <p>I have data in the database and I want to export it to CSV file.
  The data is in Japanese and for further use, I need it to be encoded in UTF-8</p>
  
  <p>This is my script to get the data and write in the CSV file</p>
  
  <pre><code>import mysql.connector
  from mysql.connector import errorcode
  
  import sys
  import csv
  
  query = 'SELECT * FROM `images-data`'
  
  try:
      cnx = mysql.connector.connect(user='root', password='1234',
                                   host='127.0.0.1',
                                   database='sotsuken-test-db')
      cur=cnx.cursor()
      cur.execute(query)
      result=cur.fetchall()
  
      c = csv.writer(open("db-data.csv","w"))
      for row in result:
          c.writerow(row)
  
  
  
  except mysql.connector.Error as err:
      if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
          print("Something is wrong with your user name or password")
      elif err.errno == errorcode.ER_BAD_DB_ERROR:
          print("Database does not exist")
      else:
          print(err)
  else:
      cnx.close()
  </code></pre>
  
  <p>I can create the CSV file, and the data is exported in UTF-8, but my CSV file's data was like this:</p>
  
  <pre><code>1,b'\xe3\x83\x86\xe3\x82\xb9\xe3\x83\x88\xe3\x81\xa7\xe3\x81\x94\xe3\x81\x8a\xe3\x81\x96\xe3\x81\x84\xe3\x81\xbe\xe3\x81\x99'
  </code></pre>
  
  <p>In my research I found that my data was written in byte object (may be I'm wrong here). I need the data to be written in UTF-8 without <code>b''</code></p>
  
  <p>I know that I can use <code>decode("UTF-8")</code> to make it into the string, but I cannot apply that to <code>csv.writerow</code></p>
  
  <p>Can you give me any suggestions?</p>