title: Python: write a list with non-ASCII characters to a text file
body: <p>I'm using python 3.4 and I'm trying to write a list of names to a text file. The list is as follows:</p>
  
  <pre><code>my_list = ['Dejan Živković','Gregg Berhalter','James Stevens','Mike Windischmann',
                 'Gunnar Heiðar Þorvaldsson']
  </code></pre>
  
  <p>I use the following code to export the list:</p>
  
  <pre><code>file = open("/Users/.../Desktop/Name_Python.txt", "w")
  file.writelines( "%s\n" % item for item in my_list )
  file.close()
  </code></pre>
  
  <p>But it does not work. Python seems not to like non-ASCII characters and gives me the following errors:</p>
  
  <pre><code>"UnicodeEncodeError: 'ascii' codec can't encode character '\u017d' in position 6: ordinal not in range(128)"
  </code></pre>
  
  <p>Do you know if there is a way to solve this problem ? Maybe it's possible to write files in UTF-8 / unicode ?</p>