0

When I split a string containing special (unknowns) characters such as new emojis (this one for instance --- > ""), Python will return it to me this way --> "\U0001f972".

s = " "
liste = s.split()
print(liste)

This returns ['\U0001f972', '\U0001f972'] but I need ['', '']

How could I make so ?

Zorpubis
  • 1
  • 1
  • Please share your code, how you are splitting the string. – Maurice Meyer Nov 09 '21 at 22:57
  • 2
    Are you certain its changing the values and its not just whatever's printing it like cmd is changing it? – Ben Nov 09 '21 at 22:57
  • It might help you to google "\U0001f972" and dig a little bit into what's going on there (after you've done that check out my name and pfp) – 0x263A Nov 09 '21 at 23:21
  • 1
    string.encode('utf-8').decode('unicode-escape') --- see https://stackoverflow.com/questions/56629083/how-to-convert-a-string-variable-with-special-characters-in-python-to-print-prop --- hopefully this works – Larry the Llama Nov 10 '21 at 00:08
  • if I use `print("\U0001f972")` then I get on screen - so it is correct character in terminal but you may need to use `print()` to see it correctly. If you use `print(repr("\U0001f972"))` then you get `"\U0001f972"` and this is how may work Python shell, Jupyter, etc if you don't use `print()`. – furas Nov 10 '21 at 00:40
  • Thank you for your consideration. I've updated the post to make it more clear. All solutions proposed above unluckily didn't do the job. Any more ideas ? – Zorpubis Nov 10 '21 at 17:57

0 Answers0