The following should be a good start:
>>> x = (u'abc/αβγ',) >>> S = type('S', (unicode,), {'__repr__': lambda s: s.encode('utf-8')}) >>> tuple(map(S, x)) (abc/αβγ,)
The idea is to create a unicode subclass that has __repr__() more to your liking.
Still trying to figure out how best to surround the result with quotes, this works for your example:
>>> S = type('S', (unicode,), {'__repr__': lambda s: "'%s'" % s.encode('utf-8')}) >>> tuple(map(S, x)) ('abc/αβγ',)
... but it will look odd if there is a single quote in the string:
>>> S("test'data") 'test'data'
source share