title: writing to text file - 'ascii' codec can't encode character
body: <p>I'm having a bit of trouble outputting words from a text-image to a <code>.txt</code> file.</p>
  
  <pre><code>import pytesseract
  from PIL import Image, ImageEnhance, ImageFilter
  
  text = pytesseract.image_to_string(Image.open("book_image.jpg"))
  
  file = open("text_file","w")
  file.write(text)
  print(text)
  </code></pre>
  
  <p>The code which reads the image file and prints out the words on the image works fine. The problem is when I try to take the text and write it to file, I get the following error;</p>
  
  <blockquote>
    <p>UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 366: ordinal not in range(128)</p>
  </blockquote>
  
  <p>Could anyone please explain how I can convert the variable <code>text</code> to a string?</p>