title: Python, Encoding output to UTF-8
body: <p>I have a definition that builds a string composed of UTF-8 encoded characters.  The output files are opened using <code>'w+', "utf-8"</code> arguments.  </p>
  
  <p>However, when I try to <code>x.write(string)</code> I get the <code>UnicodeEncodeError: 'ascii' codec can't encode character u'\ufeff' in position 1: ordinal not in range(128)</code> </p>
  
  <p>I assume this is because normally for example you would do `print(u'something').  But I need to use a variable and the quotations in u'<em>_</em>' negate that...</p>
  
  <p>Any suggestions?</p>
  
  <p>EDIT: Actual code here:</p>
  
  <pre><code>source = codecs.open("actionbreak/" + target + '.csv','r', "utf-8")
  outTarget = codecs.open("actionbreak/" + newTarget, 'w+', "utf-8")
  x = str(actionT(splitList[0], splitList[1]))
  outTarget.write(x)
  </code></pre>
  
  <p>Essentially all this is supposed to be doing is building me a large amount of strings that look similar to this:</p>
  
  <p><code>[日木曜 Deliverables]= CASE WHEN things = 11
   THEN C ELSE 0  END</code></p>