0

I'm using ruby 2.2 , and Python 2.7 . My code is :

print("\033[4;31;42mHelloWorld\033[0m")

That code works fine in Ruby . It print a colored string to the screen. But in Python , it doesn't work . Who can tell me some reasons , and if we can fix this without using third-party libraries , how to do that ? Thanks all.

  • You can't do colored text in Python without a third party module (unless you're willing to do some difficult `windll` wizardry (or equivalent for non-Windows OSes)) . Try [`colorama`](https://github.com/tartley/colorama/tree/master/colorama). Your code will work perfectly as-is if you call `colorama.init()` first. – Kevin Oct 10 '15 at 09:55
  • FWIW, your code works as expected for me using Python 2 on Linux. Are you using Python 3? If so, what happens if you specify that the string is a byte string? `print(b"\033[4;31;42mHelloWorld\033[0m")` – PM 2Ring Oct 10 '15 at 10:26
  • What operating system is this running on? – Edward Minnix Jan 07 '17 at 02:19

0 Answers0