I use a function like the following:
def stdout_encode(u, default='UTF8'):
if sys.stdout.encoding:
return u.encode(sys.stdout.encoding)
return u.encode(default)
Then my __repr__
functions look like this:
def __repr__(self):
return stdout_encode(u''.format(self.abcd, self.efgh))