Message 161151 - Python tracker
Not sure whether a solution has already been proposed because the issue is very long, but I just bumped into this on Windows and come up with this:
from __future__ import print_function
import sys
def safe_print(s):
try:
print(s)
except UnicodeEncodeError:
if sys.version_info >= (3,):
print(s.encode('utf8').decode(sys.stdout.encoding))
else:
print(s.encode('utf8'))
safe_print(u"\N{EM DASH}")
Couldn't python do the same thing internally?