<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Module: utils.PyColorize — IPython 2.3.0 documentation</title> <link rel="stylesheet" href="../../_static/default.css" type="text/css" /> <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../../', VERSION: '2.3.0', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </script> <script type="text/javascript" src="../../_static/jquery.js"></script> <script type="text/javascript" src="../../_static/underscore.js"></script> <script type="text/javascript" src="../../_static/doctools.js"></script> <link rel="top" title="IPython 2.3.0 documentation" href="../../index.html" /> <link rel="up" title="The IPython API" href="../index.html" /> <link rel="next" title="Module: utils.capture" href="IPython.utils.capture.html" /> <link rel="prev" title="Module: testing.tools" href="IPython.testing.tools.html" /> </head> <body> <div style="background-color: white; text-align: left; padding: 10px 10px 15px 15px"> <a href="http://ipython.org/"><img src="../../_static/logo.png" border="0" alt="IPython Documentation"/></a> </div> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="../../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="IPython.utils.capture.html" title="Module: utils.capture" accesskey="N">next</a> |</li> <li class="right" > <a href="IPython.testing.tools.html" title="Module: testing.tools" accesskey="P">previous</a> |</li> <li><a href="http://ipython.org">home</a>| </li> <li><a href="../../search.html">search</a>| </li> <li><a href="../../index.html">documentation </a> »</li> <li><a href="../index.html" accesskey="U">The IPython API</a> »</li> </ul> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <h3><a href="../../index.html">Table Of Contents</a></h3> <ul> <li><a class="reference internal" href="#">Module: <tt class="docutils literal"><span class="pre">utils.PyColorize</span></tt></a><ul> <li><a class="reference internal" href="#class">1 Class</a></li> <li><a class="reference internal" href="#function">1 Function</a></li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="IPython.testing.tools.html" title="previous chapter">Module: <tt class="docutils literal"><span class="pre">testing.tools</span></tt></a></p> <h4>Next topic</h4> <p class="topless"><a href="IPython.utils.capture.html" title="next chapter">Module: <tt class="docutils literal"><span class="pre">utils.capture</span></tt></a></p> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../../_sources/api/generated/IPython.utils.PyColorize.txt" rel="nofollow">Show Source</a></li> </ul> <div id="searchbox" style="display: none"> <h3>Quick search</h3> <form class="search" action="../../search.html" method="get"> <input type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> <p class="searchtip" style="font-size: 90%"> Enter search terms or a module, class or function name. </p> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="module-IPython.utils.PyColorize"> <span id="module-utils-pycolorize"></span><h1>Module: <tt class="xref py py-mod docutils literal"><span class="pre">utils.PyColorize</span></tt><a class="headerlink" href="#module-IPython.utils.PyColorize" title="Permalink to this headline">¶</a></h1> <p>Class and program to colorize python source code for ANSI terminals.</p> <p>Based on an HTML code highlighter by Jurgen Hermann found at: <a class="reference external" href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52298">http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52298</a></p> <p>Modifications by Fernando Perez (<a class="reference external" href="mailto:fperez%40colorado.edu">fperez<span>@</span>colorado<span>.</span>edu</a>).</p> <p>Information on the original HTML highlighter follows:</p> <p>MoinMoin - Python Source Parser</p> <p>Title: Colorize Python source using the built-in tokenizer</p> <p>Submitter: Jurgen Hermann Last Updated:2001/04/06</p> <p>Version no:1.2</p> <p>Description:</p> <p>This code is part of MoinMoin (<a class="reference external" href="http://moin.sourceforge.net/">http://moin.sourceforge.net/</a>) and converts Python source code to HTML markup, rendering comments, keywords, operators, numeric and string literals in different colors.</p> <p>It shows how to use the built-in keyword, token and tokenize modules to scan Python source code and re-emit it with no changes to its original formatting (which is the hard part).</p> <div class="section" id="class"> <h2>1 Class<a class="headerlink" href="#class" title="Permalink to this headline">¶</a></h2> <dl class="class"> <dt id="IPython.utils.PyColorize.Parser"> <em class="property">class </em><tt class="descclassname">IPython.utils.PyColorize.</tt><tt class="descname">Parser</tt><big>(</big><em>color_table=None</em>, <em>out=<open file '<stdout>'</em>, <em>mode 'w' at 0xf72b2078></em><big>)</big><a class="headerlink" href="#IPython.utils.PyColorize.Parser" title="Permalink to this definition">¶</a></dt> <dd><p>Format colored Python source.</p> <dl class="method"> <dt id="IPython.utils.PyColorize.Parser.__init__"> <tt class="descname">__init__</tt><big>(</big><em>color_table=None</em>, <em>out=<open file '<stdout>'</em>, <em>mode 'w' at 0xf72b2078></em><big>)</big><a class="headerlink" href="#IPython.utils.PyColorize.Parser.__init__" title="Permalink to this definition">¶</a></dt> <dd><p>Create a parser with a specified color table and output channel.</p> <p>Call format() to process code.</p> </dd></dl> <dl class="method"> <dt id="IPython.utils.PyColorize.Parser.format2"> <tt class="descname">format2</tt><big>(</big><em>raw</em>, <em>out=None</em>, <em>scheme=u''</em><big>)</big><a class="headerlink" href="#IPython.utils.PyColorize.Parser.format2" title="Permalink to this definition">¶</a></dt> <dd><p>Parse and send the colored source.</p> <p>If out and scheme are not specified, the defaults (given to constructor) are used.</p> <p>out should be a file-type object. Optionally, out can be given as the string ‘str’ and the parser will automatically return the output in a string.</p> </dd></dl> </dd></dl> </div> <div class="section" id="function"> <h2>1 Function<a class="headerlink" href="#function" title="Permalink to this headline">¶</a></h2> <dl class="function"> <dt id="IPython.utils.PyColorize.main"> <tt class="descclassname">IPython.utils.PyColorize.</tt><tt class="descname">main</tt><big>(</big><em>argv=None</em><big>)</big><a class="headerlink" href="#IPython.utils.PyColorize.main" title="Permalink to this definition">¶</a></dt> <dd><p>Run as a command-line script: colorize a python file or stdin using ANSI color escapes and print to stdout.</p> <p>Inputs:</p> <blockquote> <div><ul class="simple"> <li>argv(None): a list of strings like sys.argv[1:] giving the command-line arguments. If None, use sys.argv[1:].</li> </ul> </div></blockquote> </dd></dl> </div> </div> </div> </div> </div> <div class="clearer"></div> </div> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../../genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="../../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="IPython.utils.capture.html" title="Module: utils.capture" >next</a> |</li> <li class="right" > <a href="IPython.testing.tools.html" title="Module: testing.tools" >previous</a> |</li> <li><a href="http://ipython.org">home</a>| </li> <li><a href="../../search.html">search</a>| </li> <li><a href="../../index.html">documentation </a> »</li> <li><a href="../index.html" >The IPython API</a> »</li> </ul> </div> <div class="footer"> © Copyright The IPython Development Team. Last updated on Sep 02, 2015. Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3. </div> </body> </html>