0

Here is a simplified version of the code I am trying to run:

print "My name is \033[1;34m%s\033[1;m" % name

However, when I try to run this, it prints

My name is [1;34mBob[1;m

It appears that the backslash only escapes the 0 instead of escaping the 033. How do I fix this problem without having to download an external module? Thanks!

Sekou
  • 3
  • 3
  • 1
    It works for me (macOS Terminal.app, Python 2.7.16, `xterm-256color`). What terminal emulator are you using? What's the output of `echo $TERM`, etc? – grooveplex Aug 16 '19 at 17:24
  • 2
    Changing colors gets tricky in Windows. I would use one of the libraries mentioned in [how-to-print-colored-text-in-terminal-in-python](https://stackoverflow.com/questions/287871/how-to-print-colored-text-in-terminal-in-python) – hostingutilities.com Aug 16 '19 at 17:24
  • @grooveplex I'm using Windows Command Prompt. That might have something to do with it. – Sekou Aug 16 '19 at 17:55

1 Answers1

0

Ok, if you are using Windows, I would recommend this:

How to print colored text in terminal in Python?

The answers should work on Windows. But, in general, these work for Windows and should work for every other operating system. So, the answer with highest vote says that what it suggested should work on Windows 10. So if you are using Windows 10, then that should work for you.

new Q Open Wid
  • 2,225
  • 2
  • 18
  • 34