根据维基百科,盲文的 Unicode 块是 U+2800 .. U+28FF。
\n\n我正在尝试将普通文本转换为盲文符号(点)。为此,我正在映射此字符串:
\n\n" A1B\'K2L@CIF/MSP\\"E3H9O6R^DJG>NTQ,*5<-U8V.%[$+X!&;:4\\\\0Z7(_?W]#Y)="\nRun Code Online (Sandbox Code Playgroud)\n\n此维基百科页面提到了映射此特定字符串的原因
\n\n我的代码:
\n\ndef toBraille(c):\nunic=2800\nmapping = " A1B\'K2L@CIF/MSP\\"E3H9O6R^DJG>NTQ,*5<-U8V.%[$+X!&;:4\\\\0Z7(_?W]#Y)="\ni = mapping.index(c.upper())\nif (i>0):\n unic+=i \n unichex = hex(unic)\n return unichr(unichex))\nif (i==0):\n return \'_\'\nif (i<O):\n return \'?\'\n\ndef converter(txt):\ntmp=""\nfor x in txt:\n tmp+=str(toBraille(x))\nreturn tmp\n\ntxt = raw_input("Please insert text: \\n")\nprint(converter(txt))\nRun Code Online (Sandbox Code Playgroud)\n\n我想打印这样的盲文字符
\n\ninput = hello world\noutput = \xe2\xa0\x93\xe2\xa0\x91\xe2\xa0\x87\xe2\xa0\x87\xe2\xa0\x95 \xe2\xa0\xba\xe2\xa0\x95\xe2\xa0\x97\xe2\xa0\x87\xe2\xa0\x99\nRun Code Online (Sandbox Code Playgroud)\n\n问题是我的输出看起来像这样
\n\nInput = A\nOutput = 2801\nRun Code Online (Sandbox Code Playgroud)\n
小智 8
最好将其定义为字典,而不是两个数组。
对于盲文点:
code_table = {
'a': '100000',
'b': '110000',
'c': '100100',
'd': '100110',
'e': '100010',
'f': '110100',
'g': '110110',
'h': '110010',
'i': '010100',
'j': '010110',
'k': '101000',
'l': '111000',
'm': '101100',
'n': '101110',
'o': '101010',
'p': '111100',
'q': '111110',
'r': '111010',
's': '011100',
't': '011110',
'u': '101001',
'v': '111001',
'w': '010111',
'x': '101101',
'y': '101111',
'z': '101011',
'#': '001111',
'1': '100000',
'2': '110000',
'3': '100100',
'4': '100110',
'5': '100010',
'6': '110100',
'7': '110110',
'8': '110010',
'9': '010100',
'0': '010110',
' ': '000000'}
Run Code Online (Sandbox Code Playgroud)
对于Braille Glyph也可以进行类似的操作。
| 归档时间: |
|
| 查看次数: |
15560 次 |
| 最近记录: |