On Saturday 18 July 2015 10:52:33 Alex Naysmith wrote:
> I'm writing python scripts with the curses GUI and I need the CP437
> character set.
> 
> How can I change the character encoding in the XFCE terminal [v0.4.8] 
from
> UTF-8 to CP437 or IBM437?
> 
> Alternatively, I did attempt to change the system locale from 
en_GB.UTF-8
> to one that contained CP437/IBM437. However, no CP437 character sets
> appeared as an option in 'dpkg-configure locales' command [although 
'IBM437
> does appear as an available character set in 'locales -m'.]
> 
> Changing the system locale from UTF-8 probably isn't a good idea 
anyway, so
> it would be ideal if the character set changed was confined to the XFCE
> terminal for the purposes of the curses python script.

I don't expect it to be easy to change the terminal encoding. There is 
really no reason to do it. UTF-8 is so ubiquitous…

The best solution to your problem depends on why you need to change 
the character encoding of the terminal.

I expect both the python engine and the curse library to read UTF-8 files 
just fine and do it even better than CP437 if UTF-8 is the system encoding. 
If they don't, they are probably not correctly configured or compiled. You 
should be able to write and test your script using UTF-8.

If you really need to write your script using CP437, there are a number of 
text editors that can read and write files using whatever encoding you 
want. Vim and kwrite can both do it. There is no need to change the 
terminal encoding just to write a script with CP437.

If you need to send the script to someone that specifically requested 
CP437 encoded files, you should write and test the script using UTF-8 
(taking care of only using characters available in CP437) and then, when 
you are ready to give it away, convert it using iconv:

    iconv -f utf8 -t cp437 source -o source_in_cp437

Note that there are a number of text editors on Windows that can read 
UTF-8 files if that's your concern.

Similarly, if your python script must produce CP437 output, you can convert 
the output on the fly using iconv

   python script | iconv -f utf8 -t cp437 | other_command

That's admittedly not very convenient. So, does the python "encode" 
command (http://www.tutorialspoint.com/python/string_encode.htm) help 
you?

Frederic


Reply via email to