safaribooks
safaribooks copied to clipboard
enconding issue for 9781119508199
[#] Unhandled Exception: 'charmap' codec can't encode characters in position 85-91: character maps to
Swaping the enconding from utf-8 to utf-16 seemed to pass this problem, however why is UTF-8 prefered over UTF-16?
def out(self, put):
pattern = "\r{!s}\r{!s}\n"
try:
s = pattern.format(" " * self.columns, str(put, "utf-16", "replace"))
except TypeError:
s = pattern.format(" " * self.columns, put)
sys.stdout.write(s)