I have a string:
"123456789012"
Is it possible to print it in something like this?
print("\u1234\u5678\u9012")
using a function? ex. print_utf8(string)
I have a string:
"123456789012"
Is it possible to print it in something like this?
print("\u1234\u5678\u9012")
using a function? ex. print_utf8(string)
# Split the string into chunks of length 4
In [1]: codepoints = ["1234", "5678", "9012"]
# Convert them into the `\u` format
In [2]: r'\u' + r'\u'.join(codepoints)
Out[2]: '\\u1234\\u5678\\u9012'
# Decode
In [3]: _.encode().decode('unicode-escape')
Out[3]: 'ሴ噸递'
Note that in Python 3, strings are already in Unicode. That's why you need to .encode()
the string with Unicode escapes and then .decode()
it. See decode(unicode_escape) in python 3 a string