def rtf_encode_char(unichar):
    code = ord(unichar)
if code < 128:
    return str(unichar)
return '\\u' + str(code if code <= 32767 else code - 65536) + '?'

def rtf_encode(unistr):
    return ''.join(rtf_encode_char(c) for c in unistr)
Outputting unicode text to an RTF file in python