-1

I'm trying to print some colored text, however every method I tried failed, the Interpreter just prints the color codes as well with the text, it does not change the color any ideas why? I am using Python 3.6.8 on a Windows 10 Pro computer

Here is a code sample:

print("Blah blah \033[0;32mthis part will be green\033[00m blah blah.")

enter image description here

yarin Cohen
  • 612
  • 5
  • 16
  • 2
    Which version of Windows? You'll need Windows 10 or higher. This answer for a similar C question says use `system(" ")` to turn on VT emulation... which in the python world would be `os.system(" ")` ... I think ... https://stackoverflow.com/a/51125110/642070 – tdelaney Nov 17 '20 at 20:22
  • Sorry for not mentioning, I am using Windows 10 Pro – yarin Cohen Nov 17 '20 at 20:23
  • No, already tried this and I get the same output – yarin Cohen Nov 17 '20 at 20:30
  • @drec4s - That's a useful alternate but I don't think it answers the question of using ansi codes so can't be a duplicate. – tdelaney Nov 17 '20 at 20:30
  • Microsoft's [Console Virtual Terminal](https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences) docs reference [SetConsoleMode](https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences) which you should be able to call from the win32 extensions or ctypes. – tdelaney Nov 17 '20 at 20:33

1 Answers1

0

For anyone who might be stuck, I managed to do it with colorama just be sure to call init().

yarin Cohen
  • 612
  • 5
  • 16