3

I am trying to color a string, but it doesn't work I've tried this, but it doesn't work at the cmd window

print '\033[1;32mGreen like Grass\033[1;m'

Could someone tell me why?

In pycharm command window it does work

edtheprogrammerguy
  • 5,957
  • 6
  • 28
  • 47
user4719989
  • 107
  • 1
  • 4
  • 11

1 Answers1

0

It's probably to do with your terminal settings. When I run

python -c "print('\033[1;32mGreen like Grass\033[1;m')"

I get a green string. What value does your TERM environment variable have?

echo $TERM
xterm-256color

On Linux the termcap program handles terminal capabilities. You may just need to match TERM setting to your actual terminal emulator.

holdenweb
  • 33,305
  • 7
  • 57
  • 77