'How can I add Unicode character in status text by using Tweepy?
I want to update status with the Chinese text 我
for which the Unicode is U+6211
. I do the same thing when I add emoji in status ("\U0006211")
but it didn't work. So is it possible to update the text that is not English?
The error that I got:
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-8: truncated \UXXXXXXXX escape
Solution 1:[1]
when I use print("\u6211") it prints the correct character but as a "?" so it should work if you have the font I think
Solution 2:[2]
The \U escape sequence [...] expects eight hex digits
https://docs.python.org/3/howto/unicode.html#unicode-literals-in-python-source-code
You're providing 7 instead of 8 digits. You can simply append an extra 0: "\U00006211"
Alternatively, you can use the \u
excape sequence: "\u6211"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Bup |
Solution 2 | Harmon758 |