Convert emoji in a sentence to a word or text

I have sentences like : "This Place is awesome \xF0\x9F\x98\x89". I would like to replace the \xF0\x9F\x98\x89 with its corresponding text. hence the result be like "This palce is awesome , winking smile.". i am using python 3. i presume I can use the package emoji to demojize, but this takes the emoji rather then "\xF0\x9F\x98\x89".

mystr = "OMG the place is Awesome !!!!!!!!!!!! \xf0\x9f\x98\x9dl"
mystr = mystr.decode('utf-8')
print(emoji.demojize(mystr))

For this i get error : AttributeError: 'str' object has no attribute 'decode'

Upvotes: 0

Views: 297

Answers (1)

Shuvojit
Shuvojit

Reputation: 1470

ByteStrings start with a b notation.

>>> mystr = "OMG the place is Awesome !!!!!!!!!!!! \xf0\x9f\x98\x9dl"
>>> mystr = mystr.decode('utf-8')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'decode'
>>> mystr = b"OMG the place is Awesome !!!!!!!!!!!! \xf0\x9f\x98\x9dl"
>>> mystr = mystr.decode('utf-8')

Upvotes: 1

Related Questions