1

I am using a command-line chess game that I am taking from here. If I run the main.py part of the code using the "repl.it" or anaconda I will get what I expect: enter image description here

But if I try to run via anaconda command line or visual studio I get this: enter image description here

FFLS
  • 565
  • 1
  • 4
  • 19
  • @JoanLaraGanau you are right. My problem is if I try to copy and paste my problem in words it does not work. For example, the little question mark round with a square, if I copy and paste it disappears. – FFLS Feb 27 '20 at 21:52
  • `[34m` looks like a [shell colour code](https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux) - I think it will work in Unix shells (Linux or Mac OS), but not the windows command prompt. There are ways to install `bash` on Windows, and if you run it in `bash` it should work. – Marius Feb 27 '20 at 21:54
  • @JoanLaraGanau. This is actually a semi-decent use-case for images, since we are talking about colors. – Mad Physicist Feb 27 '20 at 22:01

1 Answers1

1

IPython, like many terminal emulators on Unix-Like systems, has built in support for ANSI Color codes. The escape characters you see in the Windows terminal are automatically converted to color commands by IPython.

You can get similar support for your python programs on Windows using the colorama library. For the output you are attempting, do

import colorama
colorama.init()

This will replace sys.stdout and sys.stderr with file objects that strip away escape sequences and perform corresponding Windows CMD operations.

If you want this to happen outside of Python as well, consider installing ansi.sys on your machine, as the colorama documentation suggests.

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264