0

I have a similar problem as explained in this post ANSI escape code wont work on python interpreter

I am using Macbook Pro and Python 3.7.0. When I give a print command with ANSI commands it prints the characters rather than take effect

>>> print ('\033[1;32;48m hello')
[1;32;48m hello

I tried with colorama and also initialized it as shown below

from colorama import init, Fore, Back, Style
init(convert=True)

Not sure what can I do to get it to print in color

khelwood
  • 46,621
  • 12
  • 59
  • 83
Tariq
  • 1
  • 2
  • 1
    When I type `print ('\033[1;32;48m hello')` into a Python session on a macbook (using iTerm2), I get text in green. Are you using the Terminal app or something else? – khelwood Jul 28 '20 at 21:04
  • 1
    This sounds like a problem with your terminal, it's working for me in iterm2 as well – juanpa.arrivillaga Jul 28 '20 at 21:14
  • @khelwood thanks for responding. I am using the default python shell that opens when I run a program. Basically I open the file from IDLE. When I hit run a new window opens which says at the top "Python 3.7.0 Shell" – Tariq Jul 30 '20 at 01:11
  • This then? [How do I print colored text in IDLE's terminal?](https://stackoverflow.com/q/42472958/3890632) – khelwood Jul 30 '20 at 07:37
  • Thanks @khelwood I tried what the article says and it basically works. From the article I understand the IDLE can only color text based on its classification like "COMMENT", "STRING", etc and not a general purpose full ANSI escape characters. I also get an extra numeric output in the result for example: color.write("Yes","STRING"), would color Yes in Green but also add a numeric value. e.g. Yes3. Anyway, thanks again. I will have to use something other than IDLE shell if I want all ANSI escape sequences to work – Tariq Jul 31 '20 at 13:28

0 Answers0