pythonunicodefontsascii

change Ascii Text Font to Unicode font in Python


I'm want to make normal text like this:

Hello

Into This:

𝓗𝓮𝓵𝓵𝓸

In python. What should I do ?


Solution

  • Your desired string 𝓗𝓮𝓵𝓵𝓸 is (character by character):

    Apply str.translate method e.g. as follows:

    import string
    
    # mathematical bold script letters
    mat_b_letters = ''.join([chr(x) for x in range(0x1D4D0, 0x1D503 + 1)])
    # ascii letters
    ascii_letters = string.ascii_uppercase + string.ascii_lowercase
    
    trans_table   = ascii_letters.maketrans( ascii_letters, mat_b_letters)
    
    print( 'Hello, StackOverflow user 19594133/God'.translate(trans_table))
    

    Result: .\SO\73426687.py

    𝓗𝓮𝓵𝓵𝓸, 𝓢𝓽𝓪𝓬𝓴𝓞𝓿𝓮𝓻𝓯𝓵𝓸𝔀 𝓾𝓼𝓮𝓻 19594133/𝓖𝓸𝓭
    

    Edit: You could choose another Latin letters script (𝐀𝐙𝐚𝐳 𝐴𝑍𝑎𝑧 𝑨𝒁𝒂𝒛 𝒜𝒵𝒶𝓏 𝓐𝓩𝓪𝔃 𝔄𝔞𝔷 𝔸𝕒𝕫 𝕬𝖅𝖆𝖟 𝖠𝖹𝖺𝗓 𝗔𝗭𝗮𝘇 𝘈𝘡𝘢𝘻 𝘼𝙕𝙖𝙯 𝙰𝚉𝚊𝚣) using their Unicode numeric values derived from the following table when computing the mat_b_letters variable - having in mind that some Unicode script does not cover all Latin letters (currently, there are holes in Unicode database version 14, for instance U+1D506 MATHEMATICAL FRAKTUR CAPITAL C or U+1D51D MATHEMATICAL FRAKTUR CAPITAL Z):