IPython does a decent job of providing console output in color on all the platforms I use it on. If you’re like me and you’ve wanted to use its coloring functionality for your own terminal output, here’s a snippet that should get you started.
[python]
from IPython import ColorANSI
from IPython.genutils import Term
tc = ColorANSI.TermColors()
red = tc.Red + "Red" + tc.Normal
print >> Term.cout, red
blue = tc.Blue + "Blue" + tc.Normal
print >> Term.cout, blue
[/python]
Assuming you have color output enabled (if you’re on Windows, you’ll need PyReadline), you should be able to %paste the plain text from the snippet above into IPython and see the output below.
Red
Blue
In newer versions of IPython (my version is 2.3.0) the same concept works, its just the imports moved around
from IPython.utils.coloransi import TermColors as tc
from IPython.utils import io
red = tc.Red + “Red” + tc.Normal
print >>io.stdout, red
blue = tc.Blue + “Blue” + tc.Normal
print >> io.stdout, blue
I hope this helps all who are still trying to do this on Windows.