0

I have created a custom font and mapped a few new characters to unmapped unicode codepoints. This works fairly well, but these characters are seemingly randomly getting converted into their codepoint representaiton ('\u2fd6' for example) instead of showing the custom font.

I've isolated the issue to a printing error when printing tuples and arrays. (perhaps more occations too.)

The following code shows when it works and when it does not. (Remember I have a custom font and do se a character where the box is, which is the desired behaivour):

char = "⿖"
print(char) # Ok

tuple = ("a", "⿖")
print(tuple) # not Ok
print(tuple[0], tuple[1]) # Ok

array = ["a", "⿖"]
print(array) # not Ok
print(array[0], array[1]) # Ok

Procuces the following output in the terminal:

⿖
('a', '\u2fd6')
a ⿖
['a', '\u2fd6']
a ⿖

I don't even know where to start. Is this a python issue? Any ideas how to avoid this conversion to unicode codepoints?

  • 2
    The documentation is a bit implicit but note:https://docs.python.org/3/library/stdtypes.html#str.isprintable *"Nonprintable characters are those characters defined in the Unicode character database as “Other” or “Separator”, excepting the ASCII space (0x20) ... (Note that printable characters in this context are those which should not be escaped when repr() is invoked on a string"* So if your Unicode codepoint is "Other" then the `repr()` of a string that contains that char will escape the char- and when you print a tuple or list, the `repr()` of the contents is used. – slothrop Jul 03 '23 at 20:53
  • 1
    (For more on tuple printing and workarounds see https://stackoverflow.com/questions/64094873/why-dont-escape-sequences-work-in-tuples) – slothrop Jul 03 '23 at 20:54
  • I believe there is a range in Unicode that is reserved for application-specific use. Are you using codepoints in those ranges? – Ulrich Eckhardt Jul 03 '23 at 21:03

0 Answers0