insomnihack

When sleep eludes, the keyboard beckons

IPython Color Console Output

December 16, 2009 Dale 1 Comment

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

Programming IPython, Python

About Me

Hi, my name's Dale, and this is my tech blog. Read More…

Search

Tags

blogging c# database Django documentation Email furniture git hacks htpc IPython Linux mac nas packaging PyCharm Python Roleplaying tools twitter unit tests virtualenv Visual Studio vmware Windows

Copyright © 2025 · Equilibre Theme on Genesis Framework · WordPress · Log in