0

I am reading (in binary) a file and the program halts when it hits b'\xe2\x80\xa6'.

'''UnicodeEncodeError: 'charmap' codec can't encode character '\u2026'
   in position 0: character maps to <undefined>
'''
print(b'\xe2\x80\xa6'.decode('utf-8')) # HORIZONTAL ELLIPSIS (U+2026)
Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132
  • I am using Windows, so the key here was to run the "Change Code Page" command: `chcp 65001` before running my script. – Mr. Polywhirl Apr 13 '19 at 04:23
  • Why are you reading the file as binary when it is encoded as UTF-8? Use `open(filename,encoding='utf8')` instead. If using Python 3.6+, it will print fine in the console because that version and later directly write Unicode to the Windows terminal instead of encoding through legacy code pages. – Mark Tolonen Apr 14 '19 at 18:08
  • I am reading a Blizzard `.stl` file, which is a database file containing Strings. – Mr. Polywhirl Apr 14 '19 at 18:16

0 Answers0