Python 3 bug print background color issue

  python, python-3.x

The standard command to color the output of print in Python 3 using ANSI escape codes seems not to be functioning.

It has to do with the changes that accompany the newest versions of Python 3, I believe.

My System: Python 3.7.3, Windows 10, IDLE.

Although it works fine on Python 2.7, with Python 3.7 it simply doesn’t function.

  • print("3[1;32;40m Bright Green n") in IDLE as shown in this article outputs [1;32;40m Bright Green. On the contrary this works fine on an online Python 2 parser giving a colored background.

  • A correction was found that on Python 3 the escape character is x1b instead of 3. A modified expression inside the print statement such as print("x1b[1;32;40m Bright Green n") in IDLE outputs [1;32;40m Bright Green and no colored background.

  • Running print("3[1;32;40m Bright Green n") on a py file still outputs [31;1;4mHello[0m
  • Since there are differences between my local system I tried to run on an online Python 3 parser print("3[1;32;40m Bright Green n") and it gave me [1;32;40m Bright Green.

This use of ANSI escape codes is mostly offered as a solution in links.

What do I do wrong?

Source: Python-3x Questions

LEAVE A COMMENT