I have a function that returns a utf-16 encoded string and I have to include its result into another string by a replace:
string = myfunc()
debug_string = debug_string.replace("$rep$", string)
In my eclipse environment it works fine, but in another environment it gives an error:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe0' in position 23: ordinal not in range(128)
Do you know what is the possible cause?
Thanks
Your string variable isn't in Unicode? Then you need to explicitly decode sequence of bytes (in UTF-16 encoding) from string (string type) to Unicode object:
u_string = myfunc().decode('utf-16')
debug_string also should be in Unicode.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With