cmd.exe on WIndows - problem with displaying some Unicode characters

Mark Lawrence breamoreboy at yahoo.co.uk
Sun Aug 3 19:20:53 EDT 2014


On 03/08/2014 23:52, Wiktor wrote:
>
> Hi,
>
> as OO programming exercise, I'm trying to port to Python one of my favorite
> game from early'90 (Atari 65XL/XE) - Kolony (here's video from original
> version on C64 https://www.youtube.com/watch?v=UFycYOp2cbE, and here's
> video from modern rewritten (for Atari emulators) version: Kolony 2106
> https://www.youtube.com/watch?v=eX20Qqqm5eg - you get the idea? ;-)).
>
> OO Design is one thing, but I want to make it look as near as possible to
> the original (those windows-like menus in console window). I tried to use
> 'standard' Unicode characters (I can see that most of my Windows monospaced
> fonts have them) to draw frame around menu. Something like this:
>
>   ┌──────────────╖
>   │ Construction ║
>   │ Production   ║
>   │ Research     ║
>   │ Exploration  ║
>   ├··············╢
>   │ Next turn    ║
>   ╘══════════════╝
>
> (I like the look of double lines on right and at the bottom)
> But when I try to print those characters, I get an error:
>
> | Traceback (most recent call last):
> |   File "E:\Moje dokumenty\python\kolony\menu.py", line 14, in <module>
> |     """
> |   File "C:\Python34\lib\encodings\cp852.py", line 19, in encode
> |     return codecs.charmap_encode(input,self.errors,encoding_map)[0]
> | UnicodeEncodeError: 'charmap' codec can't encode character '\u2556' in position 1
> | 6: character maps to <undefined>
>
> Now I know what that means. Code page that my cmd.exe is using (852)
> doesn't have "╖", "╘", "╢" and "·" symbols. Changing code page to Unicode
> (65001) doesn't really help, because all is messed up:
>   ┌──────────────╖
>   │ Construction ║
>   │ Production   ║
>   │ Research     ║
>   │ Exploration  ║
>   ├··············╢
>   │ Next turn    ║
>   ╘══════════════╝
>      �·········╢
>   │ Next turn    ║
>   ╘══════════════╝
>      ��════════════╝
>      ��═════╝
>      ═╝
> (I believe that's cmd.exe bug with Unicode support, not Python fault)
>
>
> Before I drop entirely this idea of using double lines on right and bottom
> edges, and make it look like this
>      ┌──────────────┐
>      │ Construction │
>      ├--------------┤
>      │ Next turn    │
>      └──────────────┘
> I have to ask - is there a way to make that original concept work? I know,
> that CP437 has symbols "╖", "╢" and "╘", but does not have polish letters -
> and I need to display them too.
> I also know, that cmd.exe can display those Unicode characters (by
> copy/paste them in command line or by listing filenames containing that
> characters), no matter what CP is set. How does it manage to do it? Can I
> exploit that writing my Python program?
> Wiktor
>

There are multiple known problems with cmd.exe and unicode.  A solution 
might be to use powershell, but windows being windows who really knows? :)

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence




More information about the Python-list mailing list