code: def read_txt_file(fname):
      
      encodings = ['utf-8-sig', 'cp1252']
      with open(fname, 'rb') as f:
          content = bytes(f.read())
  
      for i in encodings:
          try:
              result = content.decode(i)
              if six.PY2:
                  result = result.encode('utf-8')
              return result
          except UnicodeDecodeError:
              pass
  
      global_.FILENAME = fname
      errmsg.syntax_error(1, 'Invalid file encoding. Use one of: %s' % ', '.join(encodings))
      return ''
docs: Reads a txt file, regardless of its encoding