pythonunicode-literals

Python: How to specify and view high-numbered Unicode characters?


The Unicode character U+1d134 is the musical symbol for "common time"; it looks like a capital 'C'.

But using Python 3.6, when I specify '\U0001d134' I get a glyph that seems to indicate an unknown symbol. On my Mac, it looks like a square with a question-mark in it.

Is the inability to display the corresponding glyph simply a font limitation, or is it something else? (Like maybe something I'm doing wrong....)

For clarity, I want to use this and other such symbols in an app I'm writing, and would like to find out if there's a way to do this.


Solution

  • The problem lies not in your code but in your local system. You don't have any font installed that contains the character 𝄴 "MUSICAL SYMBOL COMMON TIME".

    That is also the reason none of your browsers can display it. Usually, browsers are quite good in hunting down any font that can display a certain character. Reason they all fail is what's in the paragraph above.

    But – as it happened,

    >>> print ('\U0001d134')
    𝄴
    

    worked for me, displaying this:

    musical symbol common time printed in Python

    I pasted it into UnicodeChecker, which helpfully listed 'all' fonts that contain this character: only one, Bravura. It's an Open Source font so go ahead and download it. (Be careful to follow proper procedures if you want to distribute it along with your app.)

    To think that I only had that font installed because of an earlier SO question.