[liblouis-liblouisxml] SV: Re: Python, please leave my Braille in peace

  • From: Bue Vester-Andersen <bue@xxxxxxxxxxxxxxxxxx>
  • To: <liblouis-liblouisxml@xxxxxxxxxxxxx>
  • Date: Wed, 16 Sep 2015 00:17:58 +0200

Thank you very much for the explanation. I guess I was trying to handle the
output as an array of integers to be cast to char, perhaps a bit C-ish.
Now it works.

Bue

-----Oprindelig meddelelse-----
Fra: liblouis-liblouisxml-bounce@xxxxxxxxxxxxx
[mailto:liblouis-liblouisxml-bounce@xxxxxxxxxxxxx] På vegne af James Teh
Sendt: 15. september 2015 00:12
Til: liblouis-liblouisxml@xxxxxxxxxxxxx
Emne: [liblouis-liblouisxml] Re: Python, please leave my Braille in peace

Technically, liblouis is supposed to output Unicode, as it deals with
widechars and talks about UCS-2 and UCS-4. What Python is doing here
isn't actually incorrect. Even if you were in C, you'd still have to
cast those characters to char to get true 8 bit, since they're 16 bit
(in Windows(.

Anyway, you can achieve what you want by calling .encode('iso8859-1') on
the resulting unicode object. The reason is that the first 8 bits of
Unicode map directly into the ISO8859-1 encoding. Note that you want
encode, not decode, since you want to encode Unicode into a character
encoding.

Jamie

On 14/09/2015 11:24 PM, Bue Vester-Andersen wrote:

Hi,

Please, I hope someone can help me solve this Python problem:

When handling Danish Braille output from Liblouis, I need to not just
handle
7-bit ASCII, but the full 8-bit range, perhaps except \x00 and \x7f (null
and delete).
Actually, the Danish 8 dot character set is built on cp1252, but with some
additional characters that are not defined in cp1252. So, I need to make
Python think that the Braille output is just some 8-bit ASCII of some code
page or other, and then make it keep its hands off my Braille, so that I
can
output it to a file as it is.

I have tried code like:

return louis.translateString([tableString], inString).decode("cp437")

Then I get the following error:

Traceback (most recent call last):
...
File "c:\python27\lib\encodings\cp437.py", line 15, in decode
return codecs.charmap_decode(input,errors,decoding_table)
UnicodeEncodeError: 'ascii' codec can't encode character u'\x98' in
position
0:
ordinal not in range(128)

Anybody has a good idea?

Bue


For a description of the software, to download it and links to
project pages go to http://liblouis.org

--
James Teh
Executive Director, NV Access Limited
Ph +61 7 3149 3306
www.nvaccess.org
Facebook: http://www.facebook.com/NVAccess
Twitter: @NVAccess
SIP: jamie@xxxxxxxxxxxx

For a description of the software, to download it and links to
project pages go to http://liblouis.org

For a description of the software, to download it and links to
project pages go to http://liblouis.org

Other related posts: