[Python] Convert text to Braille (Unicode) in Python

Discussão em 'Python' iniciado por Stack, Abril 9, 2025.

  1. Stack

    Stack Membro Participativo

    According to Wikipedia, the Unicode block for braille is U+2800 .. U+28FF.

    I'm trying to convert normal text to Braille symbols (dots). To do so, I'm mapping this string:

    " A1B'K2L@CIF/MSP\"E3H9O6R^DJG>NTQ,*5<-U8V.%[$+X!&;:4\\0Z7(_?W]#Y)="


    The reason for mapping this specific string is mentioned on this Wikipedia page

    My code:

    def toBraille(c):
    unic=2800
    mapping = " A1B'K2L@CIF/MSP\"E3H9O6R^DJG>NTQ,*5<-U8V.%[$+X!&;:4\\0Z7(_?W]#Y)="
    i = mapping.index(c.upper())
    if (i>0):
    unic+=i
    unichex = hex(unic)
    return unichr(unichex))
    if (i==0):
    return '_'
    if (i<O):
    return '?'

    def converter(txt):
    tmp=""
    for x in txt:
    tmp+=str(toBraille(x))
    return tmp

    txt = raw_input("Please insert text: \n")
    print(converter(txt))


    I want to print braille characters like this

    input = hello world
    output = ⠓⠑⠇⠇⠕ ⠺⠕⠗⠇⠙


    The problem is my output looks like this

    Input = A
    Output = 2801

    Continue reading...

Compartilhe esta Página