Cosmic
Cosmic

Reputation: 13

Changing string with escaped Unicode to normal Unicode

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

Upvotes: 1

Views: 297

Answers (1)

JosefZ
JosefZ

Reputation: 30133

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

Upvotes: 2

Related Questions