title: UnicodeDecodeError: 'charmap' codec can't encode character X at position Y: character maps to undefined
body: <p><strong>To CLARIFY: this question is not a duplicate of <a href="https://stackoverflow.com/questions/17912307/u-ufeff-in-python-string">this one</a>, I have already tried all the hints there and didn't get the answer.</strong> </p>
  
  <p>I have a txt file with unicode data in, and am want to open the file as an string. </p>
  
  <p>I tried </p>
  
  <pre><code>a=open('myfile.txt', 'r', encoding='utf-8') 
  print a.read()
  </code></pre>
  
  <p>but there is an error saying:</p>
  
  <blockquote>
    <p>UnicodeDecodeError: 'charmap' codec can't encode character '\ufeff' at
    position Y: character maps to undefined</p>
  </blockquote>
  
  <p>Now my question is, I don't care about my UTF-8 characters at all, is there anyway to put an exception that whenever python is encountering utf-8 character just remove it or pass it?   <strong>Also to clarify, I have tried the encoding with, utf-8, utf-8-sig, utf-16 and etc.</strong> </p>
  
  <p>I tried this as well but no luck.</p>
  
  <pre><code>a=open('myfile.txt', 'r', encoding='utf-8') 
  try:
      print a.read()
  except:
      pass
  </code></pre>
  
  <p>I also tried importing codecs and the code below:</p>
  
  <pre><code>a=codecs.open('myfile.txt', 'r', encoding='utf-8') 
  print a.read()
  </code></pre>
  
  <p>but still same error is popping out. </p>