{"id":138,"date":"2009-12-16T23:25:37","date_gmt":"2009-12-17T05:25:37","guid":{"rendered":"http:\/\/www.insomnihack.com\/?p=138"},"modified":"2009-12-16T23:35:03","modified_gmt":"2009-12-17T05:35:03","slug":"ipython-color-console-output","status":"publish","type":"post","link":"http:\/\/www.insomnihack.com\/?p=138","title":{"rendered":"IPython Color Console Output"},"content":{"rendered":"<p><a href=\"http:\/\/ipython.scipy.org\/moin\/\">IPython<\/a> does a decent job of providing console output in color on all the platforms I use it on. If you&#8217;re like me and you&#8217;ve wanted to use its coloring functionality for your own terminal output, here&#8217;s a snippet that should get you started.<\/p>\n<p>[python]<br \/>\nfrom IPython import ColorANSI<br \/>\nfrom IPython.genutils import Term<br \/>\ntc = ColorANSI.TermColors()<br \/>\nred = tc.Red + &quot;Red&quot; + tc.Normal<br \/>\nprint &gt;&gt; Term.cout, red<br \/>\nblue = tc.Blue + &quot;Blue&quot; + tc.Normal<br \/>\nprint &gt;&gt; Term.cout, blue<br \/>\n[\/python]<\/p>\n<p>Assuming you have color output enabled (if you&#8217;re on Windows, you&#8217;ll need <a href=\"http:\/\/ipython.scipy.org\/moin\/PyReadline\/Intro\">PyReadline<\/a>), you should be able to <span><tt>%paste<\/tt><\/span> the plain text from the snippet above into IPython and see the output below.<\/p>\n<p><span style=\"color: #ff0000;\"><tt>Red<\/tt><\/span><br \/>\n<span style=\"color: #0000ff;\"><tt>Blue<\/tt><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>IPython does a decent job of providing console output in color on all the platforms I use it on. If you&#8217;re like me and you&#8217;ve wanted to use its coloring functionality for your own terminal output, here&#8217;s a snippet that should get you started. [python] from IPython import ColorANSI from IPython.genutils import Term tc = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[23,6],"_links":{"self":[{"href":"http:\/\/www.insomnihack.com\/index.php?rest_route=\/wp\/v2\/posts\/138"}],"collection":[{"href":"http:\/\/www.insomnihack.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.insomnihack.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.insomnihack.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.insomnihack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=138"}],"version-history":[{"count":0,"href":"http:\/\/www.insomnihack.com\/index.php?rest_route=\/wp\/v2\/posts\/138\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.insomnihack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.insomnihack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=138"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.insomnihack.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}