3

Using this page How to find the unicode of the subscript alphabet? I can print all superscripts except j,l,r,w,y,s and h. Unicode clearly has coded for these superscripts but for some reason it will not work in Python. So for the other superscripts I simply write:

ua = u"\u1d43"
ub = u"\u1d47"
uc = u"\u1d9c"
ud = u"\u1d48"
ue = u"\u1d49"
uf = u"\u1da0"
ug = u"\u1d4d"
ui = u"\u2071"
uk = u"\u1d4f"
um = u"\u1d50"
un = u"\u207f"
uo = u"\u1d52"
up = u"\u1d56"
ut = u"\u1d57"
uv = u"\u1d5b"
uu = u"\u1d58"

But when I do that for the troublesome superscripts I get error message: "SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-4: truncated \uXXXX escape" As usual the error message makes no sense. Here is the code I use for the superscripts which will not work:

uw = u"\u2b7"
uy = u"\u2b8"
uj = u"\u2B2"
ul = u"\u2E1"
ur = u"\u2b3"
us = u"\u2e2"
uh = u"\u2b0"

It must have something to do with the fact that all of those superscripts start with 2 and only have 3 digits. I have also tried rewriting the codes with both uppercase and lowercase letters.

Community
  • 1
  • 1
logic1976
  • 519
  • 1
  • 6
  • 19

1 Answers1

3

Assuming Python 3, it's supposed to be a 16-bit or 32-bit hex (i.e. 4 or 8 digits) code. Your error message hints at the 4-digit requirement by saying \uXXXX:

>>> uw = u"\u2b7"
  File "<stdin>", line 1
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-4: truncated \uXXXX escape

However, you can encode your Unicode character in two other ways as well (see the documentation linked above):

>>> uw = u"\u02b7"
>>> uw = u"\u000002b7"
>>> uw = u"\N{MODIFIER LETTER SMALL W}"
>>>
Jens
  • 8,423
  • 9
  • 58
  • 78
  • Great. If it's an agreeable solution, please don't forget to accept the answer. Thanks! – Jens Feb 26 '16 at 01:21