0

I have a python script that draws a table to the console output using the extended ASCII character codes 179-218, more specifically: 179(│), 185(╣), 186(║), 187(╗), 188(╝), 200(╚), 201(╔), 202(╩), 203(╦), 204(╠), 205(═), 206(╬), 207(╧), 209(╤) and 216(╪).

I run the script on both a Windows 10 and a Windows 7 machines. On the Windows 10 machine everything shows fine, but when I run it on the Windows 7 machine, it doesn't show the characters 209(╤), 207(╧) and 216(╪) properly. When I copy-paste the character to notepad and notepad++ it shows it right as well as typing these characters directly into other places works fine. The same happens when I type the character directly to the console, I get the wrong character. Here is what is shown:

enter image description here

What is the reason for this, and is there a way to fix this?

SIMEL
  • 8,745
  • 28
  • 84
  • 130
  • It's all about [mojibake](https://en.wikipedia.org/wiki/Mojibake) (nothing to do with console font). E.g. `╧` (U+2567 = _Box Drawings Up Single And Horizontal Double_) is encoded as 207 in extended ASCII (CP 437) however code 207 is `¤` (U+00A4 _Currency Sign_) in CP850 etc… – JosefZ Mar 28 '20 at 16:02
  • @Mofi, wow that's a lot of text. I didn't really get into all of it, but from your last comment I changed the font from "raster fonts" to "Lucidia Console" (the only other option is "consolas" which also works) and it fixed the issue. You can create an answer with this and I'll accept it. – SIMEL Mar 28 '20 at 17:05

1 Answers1

1

There are two possible reasons:

  1. The code page used for encoding the characters in Python script is not the same as the code page used for the console by Windows command processor.
    The code page used by default by cmd.exe depends on region/country configured for the used account. The used code page for own user account can be seen by opening a command prompt and run the command chcp. Then it can be looked up on Wikipedia or other websites if this code page supports the characters not displayed correct at all.

  2. The used console font does not support that code page respectively character encoding.

The following answers on Stack Overflow could be useful here to understand the issue:

The default difference between console on Windows 7 and console on Windows 8/8.1/10 is the font used by default which cannot be changed from within a batch file using Windows commands.

So I suggest to compare the code page used by cmd.exe on Windows 7 and on Windows 10. On same code page used by both Windows according to configured country for the user account, I suggest to configure on Windows 7 font Consolas or Lucida Console instead of default Raster Fonts (Terminal) and check if that makes a difference.

For the font problematic see also:

By the way: On my Windows 7 machine the characters displayed on running a batch file started with a *.lnk file with Raster Fonts 10x18 (Selected Font - Terminal) configured in properties of shortcut file really look like the characters of font Terminal while the characters displayed on running cmd look like the characters of Courier New although the properties of cmd console window show Raster Fonts 8x12 (Selected Font - Terminal). I can see on just selecting 10x18 instead of 8x12 in Size in cmd properties that the look of the characters changes. So it looks like raster (bitmap) font Terminal does not support the default size 8x12 and therefore Windows uses Courier New as replacement to display the characters in default console window. The same behavior can be seen by me on my Windows XP machine. It is strange that Microsoft defined raster font Terminal as default font on Windows XP/Vista/7, but none of the *.fon files of this font supports the default font size 8x12 and so the replacement font Courier New is used to display the characters in default console window.

Mofi
  • 46,139
  • 17
  • 80
  • 143