<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Python Blog - All about python &#187; alternate print</title>
	<atom:link href="http://www.python-blog.com/tag/alternate-print/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.python-blog.com</link>
	<description>and technologies around</description>
	<lastBuildDate>Tue, 27 Jul 2010 19:58:17 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>alternate &#8220;preaty&#8221; print method.</title>
		<link>http://www.python-blog.com/2010/01/01/alternate-preaty-print-method/</link>
		<comments>http://www.python-blog.com/2010/01/01/alternate-preaty-print-method/#comments</comments>
		<pubDate>Fri, 01 Jan 2010 20:47:29 +0000</pubDate>
		<dc:creator>Marcin Kuźmiński</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[alternate print]]></category>
		<category><![CDATA[debug printing for collections]]></category>
		<category><![CDATA[pprint]]></category>

		<guid isPermaLink="false">http://www.python-blog.com/?p=220</guid>
		<description><![CDATA[I always loved how the print_r() function worked in php. In python print does print everything but when large collections (ie huge dicts) are printed using print  you could get lost in the output. I just discovered a little smarter print function called pprint from module pprint

from pprint import pprint

This is great for debugging [...]]]></description>
			<content:encoded><![CDATA[<p>I always loved how the print_r() function worked in php. In python print does print everything but when large collections (ie huge dicts) are printed using print  you could get lost in the output. I just discovered a little smarter print function called pprint from module pprint</p>
<pre class="brush:python">
from pprint import pprint
</pre>
<p>This is great for debugging something in collections. Pprint prints in a nicer human readable form types of data like : list,dict,tuples.</p>
<pre class="brush:python">
l = [x for x in range(100)]
l.insert(0, l[:])
pprint(l)
l = dict([(x, x) for x in range(100)])

pprint(l)
#this will print this list in more convinient way
{0: 0,
 1: 1,
 2: 2,
 3: 3,
 4: 4,
 5: 5,
 6: 6,
 7: 7,
 8: 8,
 9: 9,
 ...
 98: 98,
 99: 99}
</pre>
<p>There are two interesting arguments in pprint function the:<br />
        width<br />
            Attempted maximum number of columns in the output.<br />
       width=100 will wrap everything that outputs longer than 100 chars.<br />
and<br />
        depth<br />
            The maximum depth to print out nested structures.<br />
ie:</p>
<pre class="brush:python">
pprint.pprint(stuff, depth=3)
['aaaaaaaaaa',
 ('spam', ('eggs', (...))),
 ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'],
 ['cccccccccccccccccccc', 'dddddddddddddddddddd']]
#now as you can see the tuples at index 1 have a depth of more than 3 and #they are being reduced by the pprint. Imagine how this helps with debuggin a
#really complicated structures.
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.python-blog.com/2010/01/01/alternate-preaty-print-method/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
