1

I've got a string which looks like this, made up of normal characters and one single escaped Unicode character in the middle:

reb\u016bke

I want to have Python convert the whole string to the normal Unicode version, which should be rebūke. I've tried using str.encode(), but it doesn't seem to do very much, and apparently decode doesn't exist anymore? I'm really stuck!

EDIT: Output from repr is reb\\\u016bke

4
  • 2
    Could you print the 5th character? It is 0 or k? Possibly it is just the console that show you the \u notation (so check how to have UTF-8 console, there are many questions here). Else the question is legit (unescaping a string) Commented Oct 21, 2020 at 15:31
  • Post the output you get when you do a print(repr(your_variable_here)) Commented Oct 21, 2020 at 15:36
  • So the full correct string should be 'rebūke', meaning the unicode character 'ū' must be represented as '\u016b'. I.e. the fifth character should therefore be a 'k'. Can Python pick out the '\u016b' in the middle of the string and convert it to unicode? Commented Oct 21, 2020 at 15:36
  • The output from repr is 'reb\\u016bke' Commented Oct 21, 2020 at 15:39

1 Answer 1

2

If I try reproducing your issue:

s="reb\\u016bke"; print(s); # reb\u016bke print(repr(s)); # 'reb\\u016bke' print(s.encode().decode('unicode-escape')); # rebūke 
Sign up to request clarification or add additional context in comments.

1 Comment

Aaah fantastic! Thanks so much!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.