title: How to write unicode strings into a file?
body: <p>I am using python 2.6.5
  I want to write some japanese characters to a file.
  I am getting this error &amp; I don't know how to change the encoding.</p>
  
  <pre><code>Python 2.6.5 (r265:79063, Jun 12 2010, 17:07:01)
  [GCC 4.3.4 20090804 (release) 1] on cygwin
  &gt;&gt;&gt; s = u'\u5E73\u621015'
  &gt;&gt;&gt; with open("yop", "wb") as f:
  ...   f.write( s + "\n" );
  ...
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 2, in &lt;module&gt;
  UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: 
    ordinal not in range(128)
  &gt;&gt;&gt; type( s )
  &lt;type 'unicode'&gt;
  </code></pre>