I am using python3 to receive and process text messages from a telegram channel. I sometimes get messages containing a string like this:
Ехchanges: Віnance Futures
Looking pretty normal. But when I want to check
if 'Exchanges' in the_string:
I get
False
Trying to track this down:
the_string.encode()
yields
b'xd0x95xd1x85changes: xd0x92xd1x96nance Futures'
How can I convert this to a usual string?
'Exchanges: Binance Futures'
2
Answers
Try to use encode() and decode() methods of the str class mixed together:
It’s
utf-8
encoded string. You need to use string decoderdecode('utf-8')
here.Solution: