<?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>Musings of an Anonymous Geek &#187; Uncategorized</title>
	<atom:link href="http://www.protocolostomy.com/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.protocolostomy.com</link>
	<description>Made with only the finest 1's and 0's</description>
	<lastBuildDate>Thu, 03 Nov 2011 04:08:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Book Review: Python Standard Library by Example</title>
		<link>http://www.protocolostomy.com/2011/06/02/book-review-python-standard-library-by-example/</link>
		<comments>http://www.protocolostomy.com/2011/06/02/book-review-python-standard-library-by-example/#comments</comments>
		<pubDate>Fri, 03 Jun 2011 00:08:10 +0000</pubDate>
		<dc:creator>bkjones</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.protocolostomy.com/?p=918</guid>
		<description><![CDATA[Quick Facts: Author: Doug Hellmann Pages: 1344 Publisher: Addison-Wesley (Developer&#8217;s Library) ETA: June 5, 2011 Amazon link: http://www.amazon.com/Python-Standard-Library-Example-Developers/dp/0321767349/ref=sr_1_1?ie=UTF8&#38;qid=1307109464&#38;sr=1-1-spell What this book says it does: From the book&#8217;s description: This book is a collection of essays and example programs demonstrating how to use more than 100 modules from Python standard library. It goes beyond the documentation [...]]]></description>
			<content:encoded><![CDATA[<h2>Quick Facts:</h2>
<ul>
<li>Author: <a href="http://www.doughellmann.com/">Doug Hellmann</a></li>
<li>Pages: 1344</li>
<li>Publisher: Addison-Wesley (Developer&#8217;s Library)</li>
<li>ETA: June 5, 2011</li>
<li>Amazon link: http://www.amazon.com/Python-Standard-Library-Example-Developers/dp/0321767349/ref=sr_1_1?ie=UTF8&amp;qid=1307109464&amp;sr=1-1-spell</li>
</ul>
<h2>What this book says it does:</h2>
<p>From the book&#8217;s description:</p>
<blockquote><p>This book is a collection of essays and example programs demonstrating how to use more than 100 modules from Python standard library. It goes beyond the documentation available on python.org to show real programs using the modules and demonstrating how you can use them in your daily programming tasks.</p></blockquote>
<h2>What this book actually does:</h2>
<p>This book actually kinda rocks, in part because of its a unique take on documentation of the Python standard library. The Python standard library documentation is actually a pretty good high-level reference, and this book doesn&#8217;t seek to duplicate what&#8217;s there. Instead, it specifically seeks out places in the existing documentation that are underdocumented, undocumented, don&#8217;t have clear enough examples, or just don&#8217;t provide the value to the end user that they should for whatever reason. Even as good as the standard library documentation is, Doug easily cranked out 1000+ pages of invaluable information that has given me a much greater insight into the standard library modules that I use on a regular basis (and plenty that I don&#8217;t use on a regular basis).</p>
<h2>How it works</h2>
<p>The book is simply laid out by module. Using the multiprocessing module? It&#8217;s right there in the Table of Contents. It&#8217;s as easy to use as the standard library docs from a navigational perspective, and the index, it could be argued, is an improvement over docs.python.org&#8217;s  search behavior.</p>
<p>When you get to the module you&#8217;re looking for, you&#8217;ll primarily see code. There is enough English text to explain what the code actually does, but the main illustrative tool in this book is the code. This is not an easy thing to accomplish, but Doug provides a very nice and balanced presentation of the real meaty parts of your favorite standard library modules.</p>
<h2>What&#8217;s Great About it</h2>
<p>First, it provides both depth and breadth, it&#8217;s easy to find whatever you&#8217;re looking for, and if it&#8217;s not needed (usually because it&#8217;s well-covered in the standard library docs) it&#8217;s not there.</p>
<p>Second, the book is written by an authoritative, knowledgeable, experienced, and prolific Python developer. While he&#8217;s a creative thinker, his work is balanced by a healthy dose of pragmatism and grounded in best practices. Contrived as the examples might get at times, you won&#8217;t typically find code written by Doug that would garner sideways glances by experienced Python developers.</p>
<p>Third, it&#8217;s not a rehashing of the docs. In fact it skips coverage of things that are well-documented in the docs. Yes, the book does contain simple introductory material for each module to give the uninitiated some context, but that&#8217;s different from a book that takes existing docs and just moves the letters around. Doug does a great job of getting you into the good stuff without much fluff.</p>
<p>Fourth, there&#8217;s almost zero fluff. I&#8217;d love to see a statistical breakdown of the number of lines of code vs. text in this book. And the good part really isn&#8217;t that he&#8217;s put so much code in the book, it&#8217;s that he presents with code alongside the text in a way that insures readers don&#8217;t get lost.</p>
<p>Fifth, this wasn&#8217;t a rush job. Doug has been writing this content in the form of his <a href="http://www.doughellmann.com/PyMOTW/" target="_blank">Python Module of the Week blog series</a> for a few years now. Most of the work was editing, finessing, updating, and testing (and retesting) the code, not developing the content from scratch. So what&#8217;s there in the book is not just a braindump from Doug&#8217;s brain: it&#8217;s had the benefit of peer review and feedback from the blog, email, etc., and that adds a ton of value to the final product in my eyes.</p>
<h2>What&#8217;s Not Great About it</h2>
<p>I insist on including bad things about everything I review, because nothing is perfect, and the more people talk about things they don&#8217;t like, the more makers start to listen and make things better.</p>
<p>To be honest, the only thing I found lacking in this book is the index. This should not shock anyone who is a tech bibliophile. Most indexes, at least on tech books, are pretty bad (ironic since tech books often serve as references, which makes the index pretty crucial). Also, consider that this review is based on a review copy of the book, so it&#8217;s possible that the final version will have a totally awesome index.</p>
<p>Ah, one other thing (which also might be due to this being a review copy): there are no tab markers. Since Python defines scope using whitespace, not having indentation markers in any medium containing page breaks can lead to confusion if a code sample crosses page boundaries. The alternative to having the markers is to insure that the code samples don&#8217;t cross page boundaries. It&#8217;s not possible for me to know if they&#8217;ll do one or both of these before the final printing.</p>
<h2>The Final Word</h2>
<p>My petty complaints about the index and indentation markers are not only trivial, but they both may be fixed in the final printing. I saw nothing so bad that I wouldn&#8217;t highly recommend this book, and I&#8217;ve seen tons and tons of stuff that <em>would</em> make me highly recommend this book. I&#8217;m using this book myself on a fairly regular basis, and it&#8217;s an effective, easy-to-use tool that makes a great companion reference to the standard library.</p>
<p><a href="http://www.amazon.com/Python-Standard-Library-Example-Developers/dp/0321767349/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1307059386&amp;sr=8-1" target="_blank">Buy it. </a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.protocolostomy.com/2011/06/02/book-review-python-standard-library-by-example/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Lessons Learned Porting Dateutil to Python 3</title>
		<link>http://www.protocolostomy.com/2011/02/25/lessons-learned-porting-dateutil-to-python-3/</link>
		<comments>http://www.protocolostomy.com/2011/02/25/lessons-learned-porting-dateutil-to-python-3/#comments</comments>
		<pubDate>Sat, 26 Feb 2011 04:04:45 +0000</pubDate>
		<dc:creator>bkjones</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.protocolostomy.com/?p=903</guid>
		<description><![CDATA[The dateutil module is a very popular third-party (pure) Python module that makes it easier (and in some cases, possible) to perform more advanced manipulations on dates and date ranges than simply using some combination of Python&#8217;s &#8216;included batteries&#8217; like the datetime, time and calendar modules. Dateutil does fuzzy date matching, Easter calculations in the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://niemeyer.net/python-dateutil">The dateutil module</a> is a very popular third-party (pure) Python module that makes it easier (and in some cases, possible) to perform more advanced manipulations on dates and date ranges than simply using some combination of Python&#8217;s &#8216;included batteries&#8217; like the datetime, time and calendar modules.</p>
<p>Dateutil does fuzzy date matching, Easter calculations in the past and future, relative time delta calculations, time zone manipulation, and lots more, all in one nicely bundled package.</p>
<p>I decided to port dateutil to Python 3.</p>
<h3>Why?</h3>
<p>For those who haven&#8217;t been following along at home, <a href="http://www.dabeaz.com">David Beazley</a> and I are working on the upcoming Python Cookbook 3rd Edition, <a href="http://www.protocolostomy.com/2010/12/16/good-things-come-in-threes-python-cookbook-third-edition/">which will contain only Python 3 recipes</a>. Python 2 will probably only get any real treatment when we talk about porting code.</p>
<p>When I went back to the 2nd edition of the book to figure out what modules are used heavily that might not be compatible with Python 3, dateutil stuck out. It&#8217;s probably in half or more of the recipes in the &#8216;Time and Money&#8217; chapter in the 2nd Edition. I decided to give it a look.</p>
<h3>How Long Did it Take?</h3>
<p>Less than one work day. Seriously. It was probably 4-5 hours in total, including looking at documentation and getting to know dateutil. I downloaded it, I ran 2to3 on it without letting 2to3 do the in-place edits, scanned the output for anything that looked ominous (there were a couple of things that looked a lot worse than they turned out to be), and once satisfied that it wasn&#8217;t going to do things that were dumb, I let &#8216;er rip: I ran 2to3 and told it to go ahead and change the files (2to3 makes backup copies of all edited files by default, by the way).</p>
<h3>What Was the Hardest Part?</h3>
<p>Well, there were a few unit tests that used the <a href="http://docs.python.org/py3k/library/base64">base64</a> module to decode some time zone file data into a <a href="http://docs.python.org/py3k/library/io#io.StringIO">StringIO</a> object before passing the file-like object to the code under test (I believe the code under test was the relativedelta module). Inside there, the file-like StringIO object is subjected to a bunch of <a href="http://docs.python.org/py3k/library/struct#struct.unpack">struct.unpack()</a> calls, and there are a couple of plain strings that get routed elsewhere.</p>
<p>The issue with this is that there are NO methods inside the base64 module that return strings anymore, which makes creating the StringIO object more challenging. All base64 methods return Python bytes objects. So, I replaced the StringIO object with a <a href="http://docs.python.org/py3k/library/io#io.BytesIO">BytesIO</a> object, all of the struct.unpack() calls &#8220;just worked&#8221;, and the strings that were actually needed as strings in the code had a &#8216;.decode()&#8217; appended to them to convert the bytes back to strings. All was well with the world.</p>
<h3>What Made it Easier?</h3>
<p>Two things, smaller one first:</p>
<p>First, Python built-in modules for date handling haven&#8217;t been flipped around much, and dateutil doesn&#8217;t have any dependencies outside the standard library (hm, maybe that&#8217;s 2 things right there). The namespaces for date manipulation modules are identical to Python 2, and I believe for the most part all of the methods act the same way. There might be some under-the-hood changes where things return <a href="http://docs.python.org/py3k/library/stdtypes.html#memoryview-type">memoryview</a> objects or iterators instead of lists or something, but in this and other porting projects involving dates, that stuff has been pretty much a non-event most of the time</p>
<p><em>But the A #1 biggest thing that made this whole thing take less than a day instead of more than a week? Tests. </em></p>
<p>Dateutil landed on my hard drive with <a href="http://bazaar.launchpad.net/~niemeyer/dateutil/trunk/view/head:/test.py">478 tests</a> (the main module has about 3600 lines of actual code, and the tests by themselves are roughly 4000 lines of code). As a result, I didn&#8217;t have to manually check all kinds of functionality or write my own tests. I was able to port the tests fairly easily with just a couple of glitches (like the aforementioned base64 issue). From there I felt confident that the tests were testing the code properly.</p>
<p>In the past couple of days since I completed the &#8216;project&#8217;, I ported some of the dateutil recipes from the 2nd edition of the book to Python 3, just for some extra assurance. I ported 5 recipes in under an hour. They all worked.</p>
<h3>Had You Ported Stuff Before?</h3>
<p>Well, to be honest most of my Python 3 experience (pre-book, that is) is with writing new code. To gain a broader exposure to Python 3, I&#8217;ve also done lots of little code golf-type labs, impromptu REPL-based testing at work for things I&#8217;m doing there, etc. I have ported a couple of other small projects, and I have had to solve a couple of issues, but it&#8217;s not like I&#8217;ve ever ported something the size of Django or ReportLab or something.</p>
<h3>The Best Part?</h3>
<p>I had never seen dateutil in my life.</p>
<p>I had read about it (I owned the Python Cookbook 2nd Edition since its initial release, after all), but I&#8217;d never been a user of the project.</p>
<h3>The Lessons?</h3>
<ol>
<li>This is totally doable. Stop listening to the fear-inducing rantings of naysayers. Don&#8217;t let them hold you back. The pink ponies are in front of you, not behind you.</li>
<li>There are, in fact, parts of Python that remain almost unchanged in Python 3. I would imagine that even Django may find that there are swaths of code that &#8220;just works&#8221; in Python 3. I&#8217;ll be interested to see metrics about that (dear Django: keep metrics on your porting project!)</li>
<li>Making a <a href="http://docs.python.org/release/3.0.1/whatsnew/3.0.html#text-vs-data-instead-of-unicode-vs-8-bit">separation between text and data</a> in the language is actually a good thing, and in the places where it bytes you (couldn&#8217;t resist, sorry), it will likely make sense if you have a fundamental understanding of why text and data aren&#8217;t the same thing. I predict that, in 2012, most will view complainers about this change the same way we view whitespace haters today.</li>
</ol>
<h3>&#8220;I Can&#8217;t Port Because&#8230;&#8221;</h3>
<p>If you&#8217;re still skeptical, or you have questions, or you&#8217;re trying and having real problems, Dave and I would both love for *you* to come to our <a href="http://us.pycon.org/2011/schedule/presentations/274/">tutorial at PyCon</a>. Or just come to PyCon so we can hack in the hallway on it. I&#8217;ve ported, or am in the process of porting, 3 modules to Python 3. Dave has single-handedly ported something like 3-5 modules to Python 3 in the past 6 weeks or so. He&#8217;s diabolical.</p>
<p>I&#8217;d love to help you out, and if it turns out I can&#8217;t, I&#8217;d love to learn more about the issue so we can shine a light on it for the rest of the community. Is it a simple matter of documentation? Is it a bug? Is it something more serious? Let&#8217;s figure it out and leverage the amazing pool of talent at PyCon to both learn about the issue and hopefully get to a solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.protocolostomy.com/2011/02/25/lessons-learned-porting-dateutil-to-python-3/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>PyCon 2011 Predictions</title>
		<link>http://www.protocolostomy.com/2011/01/28/pycon-2011-predictions/</link>
		<comments>http://www.protocolostomy.com/2011/01/28/pycon-2011-predictions/#comments</comments>
		<pubDate>Fri, 28 Jan 2011 21:39:43 +0000</pubDate>
		<dc:creator>bkjones</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.protocolostomy.com/?p=898</guid>
		<description><![CDATA[PyCon 2011 is right around the corner. Are you going? You should. The talks are sick. You can still register &#8211; it&#8217;s too late to be an early bird, but registration is still open! Well, I am, and I&#8217;m here to get the rumor mill started by sharing some predictions for this year&#8217;s PyCon. Packaging [...]]]></description>
			<content:encoded><![CDATA[<p>PyCon 2011 is right around the corner. Are you going? You should. <a href="http://us.pycon.org/2011/schedule/lists/talks/">The talks are sick</a>. You can still register &#8211;<a href="http://pycon.blogspot.com/2011/01/pycon-2011-early-bird-may-be-over-but.html"> it&#8217;s too late to be an early bird, but registration is still open! </a></p>
<p>Well, I am, and I&#8217;m here to get the rumor mill started by sharing some predictions for this year&#8217;s PyCon.</p>
<h2>Packaging</h2>
<p>While last year there was some hubbub around packaging, most notably the <a href="http://s3.pixane.com/pip_distribute.png">poster images declaring that pip and distribute were &#8216;the new black&#8217;</a>, this year that&#8217;s old news. The pip and distribute mantra will bear repeating for those who are still behind the times of course, but this year I think there will be more hand-wringing over packaging, probably focusing more on the data and distribution mechanism than the tools. I, for one, am <a href="http://us.pycon.org/2011/schedule/sessions/81/">looking forward to any light Tarek Ziade</a> and other&#8217;s on the distutils2 team can shed on new metadata elements, new build procedures (I hear setup.py is going away someday), and what&#8217;s going on with distutils, distribute, pip, distutils2, PyPI, etc.</p>
<p>My prediction? Packaging, while not very exciting, will garner a lot of attention again this year.</p>
<h2>Python 3</h2>
<p>Dave Beazley and I will be doing a <a href="http://us.pycon.org/2011/schedule/sessions/274/">tutorial on Python 3</a>, but besides that, I think there&#8217;s going to be a lot of hallway (and lounge) discussion about <a href="http://us.pycon.org/2011/schedule/sessions/21/">all</a> <a href="http://us.pycon.org/2011/schedule/sessions/96/">things</a> <a href="http://us.pycon.org/2011/schedule/sessions/238/">Python</a> <a href="http://us.pycon.org/2011/schedule/sessions/266/">3</a>. This would mirror the clamor around the topic recently online, which I don&#8217;t really expect to slow down. Python 3 is, of course, discussed every year, but I think this year&#8217;s PyCon will be Python 3&#8242;s Woodstock: the time and place where minds merge onto an idea together and harmonize and all that stuff.</p>
<p>My prediction? We&#8217;ll see a good number of commitments from projects to port to Python 3, GSOC projects related to Python 3, and more funny looks at projects not getting their porting underway in 2011 as a direct result of PyCon 2011.</p>
<h2>Scale</h2>
<p>Multiprocessing and threading will be hot topics again for two reasons: First, lots of people just look at the GIL and reflexively get heartburn without doing any actual analysis to see if they even need to care about it in the context of a particular application. Second, the uptake for Python in &#8216;web scale&#8217; environments continues to grow, so that&#8217;s bound to be reflected in the attendee demographics if you will, and therefore the perceived interest in the topic.</p>
<p><a href="http://us.pycon.org/2011/schedule/sessions/160/">PyPy</a> is going to loom large at this year&#8217;s conference. Some may decide after PyCon 2011 that PyPy is the future for them. Unladen Swallow will be declared dead, in spite of some eager undergrads making empty promises about picking it up. Most who care will opt for the project that appears to be gaining steam, not losing it.</p>
<p>Generator-based coroutines will continue to be a really cool but relatively unused oddity, and Eventlet and the like will continue to have their adherents and go with the flow.</p>
<p>Event-based/async frameworks will garner some attention. Tornado, gUnicorn, and others will do well. Twisted followers will say that all others are either redundant or fatally flawed.</p>
<p>My prediction? <a href="http://us.pycon.org/2011/schedule/sessions/35/">Tornado</a> and <a href="http://us.pycon.org/2011/schedule/sessions/98/">ZeroMQ</a> will make a big splash, this being the first year it&#8217;s being covered (I think). People will still advocate multiprocessing over threading after the conference, and <a href="http://us.pycon.org/2011/schedule/sessions/208/">Twisted</a> will start to see declines in usership after PyCon 2011.</p>
<h2>Potpourri</h2>
<ul>
<li>Python core development contributions will increase thanks to <a href="http://us.pycon.org/2011/schedule/sessions/7/">efforts</a> by the PSF and <a href="http://us.pycon.org/2011/schedule/sessions/141/">core</a> development communities, though not without some growing pains.</li>
<li>Michael Foord&#8217;s &#8216;<a href="http://us.pycon.org/2011/schedule/sessions/34/">mock</a>&#8216; library will take off as a de facto standard module in the toolbelts of Python developers everywhere.</li>
<li>Fabric&#8217;s parallel branch will be merged as the default either before or as a result of activity at PyCon 2011.</li>
<li><a href="http://us.pycon.org/2011/schedule/sessions/121/">Flask</a> will announce a merger with another web framework in 2011, in part due to conversations and activity at PyCon.</li>
<li>PyCharm will become recognized as the preeminent <a href="http://us.pycon.org/2011/schedule/sessions/270/">Python IDE</a> as a result of everyone getting to PyCon only to find that everyone else they were going to advocate it to is already using it.</li>
<li>Some outside the scientific community will attend a Python-Science talk anyway and come away with valuable techniques they can apply to distributed computing problems. Some outside the web scalability domain will attend related talks anyway and take something back to the enterprise computing space. Some outside the cloud space will attend a cloud talk and find a cool project to put in the cloud. As a result:</li>
<li>At least 30 new Python projects will be created as a direct result of PyCon 2011.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.protocolostomy.com/2011/01/28/pycon-2011-predictions/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>The Makings of a Great Python Cookbook Recipe</title>
		<link>http://www.protocolostomy.com/2010/12/20/the-makings-of-a-great-python-cookbook-recipe/</link>
		<comments>http://www.protocolostomy.com/2010/12/20/the-makings-of-a-great-python-cookbook-recipe/#comments</comments>
		<pubDate>Mon, 20 Dec 2010 13:03:59 +0000</pubDate>
		<dc:creator>bkjones</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Sysadmin]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.protocolostomy.com/?p=885</guid>
		<description><![CDATA[I&#8217;ve seen some comments on Twitter, Buzz, Reddit, and elsewhere, and we&#8217;ve gotten some suggestions for recipes already via email (thanks!), and both Dave and I thought it&#8217;d be good to present a simple-to-follow &#8216;meta-recipe&#8217;; a recipe for making a great recipe that has a good shot at making it into the cookbook. So let&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve seen some comments on Twitter, Buzz, Reddit, and elsewhere, and we&#8217;ve gotten some suggestions for recipes already via email (thanks!), and both Dave and I thought it&#8217;d be good to present a simple-to-follow &#8216;meta-recipe&#8217;; a recipe for making a great recipe that has a good shot at making it into the cookbook.</p>
<p>So let&#8217;s get down to what makes a good recipe. These are in no particular order:</p>
<h3>Concise</h3>
<p>When you read a recipe for apple pie, it doesn&#8217;t include a diatribe about how to grow and pick apples. This is in part because of space constraints (the book would be huge, or the coverage would be incomplete, take your pick). It&#8217;s also partly because you can probably assume that the reader has somehow procured apples and assumes they&#8217;ll need them for this recipe and all of that.</p>
<p>In a recipe for, say, an ETL script that hopes to illustrate Python&#8217;s useful string manipulation features, you probably don&#8217;t need to spend much time explaining what a database is, or take a lot of lines of code to deal with the database. It makes the code longer, and just distracts from the string manipulation goodness you&#8217;re trying to relay to the reader.</p>
<p>Short and sweet. &#8220;Everything you need, nothing you don&#8217;t&#8221;.</p>
<h3>Illustrative</h3>
<p>Recipes for the cookbook should be relatively narrowly focused on illustrating a particular technique, module (built-in or otherwise), or language feature, and bringing it to life. It need not be illustrative of a business process, remotely associated technology, etc.</p>
<p>So, if you want to write a recipe about os.walk, you don&#8217;t need to get into the semantics of the ext3 filesystem implementation, because that&#8217;s not what you&#8217;re trying to illustrate.</p>
<h3>Practical</h3>
<p>Above I noted that the recipe should be relatively narrowly focused <strong>on a technique or language feature</strong>. It should NOT be narrowly focused in terms of its applicability.</p>
<p>For example, if you wanted to illustrate the usefulness of the Python csv module, awesome! And if you want to mention that csv will attempt to make its output usable in Excel, awesome! But if you wanted to write a recipe called &#8220;Supporting Windows &#8217;95 Excel Clients With Python&#8221; dealing only with Excel, specifically on Windows &#8217;95, well&#8230; that&#8217;s really specific, and really a &#8216;niche&#8217; recipe. It&#8217;d be better left for some future &#8216;Python Hacks&#8217; book or something.</p>
<p>When you read a cookbook, you probably don&#8217;t seek out &#8220;How to make mulligatawny soup in a Le Creuset™ Dutch Oven Using an Induction Stove at 30,000 Feet&#8221;. Likewise, in order to be useful to a wider audience, your recipe should ideally not force so many assumptions onto readers who just want to make a good meal (so to speak).</p>
<p>Our devotion to the practical also means we don&#8217;t plan to include any recipes dealing with Fibonacci numbers, factorials, or the like. Leave those for some future &#8220;Python Homework Problems&#8221; book.</p>
<h3>Well-Written</h3>
<p>By &#8216;well-written&#8217;, I&#8217;m partially just lumping everything I just said all together under one title. However, in addition, I would ask that recipe authors resist the temptation to utilize unnecessary &#8216;cleverness&#8217; that might make the code harder to read and understand, or be a distraction from what you&#8217;re trying to relay to the reader.</p>
<p>Just because you can get the job done with a nested list comprehension doesn&#8217;t mean you should. Open up in the code listing to allow easy comprehension by readers at all levels. If you must use nested list comprehensions, perhaps it warrants a separate recipe?</p>
<p>Nested list comprehensions are just an example, of course. I&#8217;m sure you can think of others. When you&#8217;re looking at your recipe, just ask yourself if there&#8217;s a simpler construct, technique, or idiom that can be used to achieve the same goal.</p>
<h3>Pythonic</h3>
<p>In general, follow the &#8216;import this&#8217; rules like you would with any other Python code you write. &#8220;Sparse is better than dense&#8221;, &#8220;Readability counts&#8221;, etc. In addition, bonus points are given for following <a href="http://www.python.org/dev/peps/pep-0008/">PEP 8</a>.</p>
<p>But I&#8217;m not just talking about the code. Long-time Python coders (or maybe even not-so-long-time ones) come to realize that the Zen of Python applies not just to code, but to the way you think about your application. When Dave and I are reading recipe descriptions, we&#8217;re thinking in that mode. &#8220;Would we do this? Why would we do this? When would we do this? Is there a more Pythonic solution to this problem? Can this solution be made more Pythonic?&#8221;</p>
<h3>When in doubt&#8230;</h3>
<p>If you&#8217;re not sure about any of that, your default action should be to <a href="http://code.activestate.com/recipes/langs/python/tags/meta:min_python_3/">post your recipe on the ActiveState site</a>. The reality is that posting a recipe there will help both the community and yourself. The feedback you get on your recipe will help you become a better coder, and it&#8217;ll help people evaluating your recipe to make sound decisions and perhaps consider things they hadn&#8217;t. It&#8217;s good all over. Getting into the book is just a nice cherry on the sundae.</p>
<p>Also, while unit tests are fantastic, they&#8217;re not expected to show up along with the recipe. ActiveState to my knowledge doesn&#8217;t have a mechanism for easily including test code alongside (but not embedded in) the recipe code. If you want to use doctest, great. If you want to point us at a recipe you&#8217;ve posted, you can include tests in that email, or not. It&#8217;s totally unnecessary to include them, although they are appreciated.</p>
<h3>Questions?</h3>
<p>If you have questions, email them to Dave and I at PythonCookbook at oreilly dot com. You can also post questions here in the comments of this post.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.protocolostomy.com/2010/12/20/the-makings-of-a-great-python-cookbook-recipe/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Good Things Come in Threes: Python Cookbook, Third Edition</title>
		<link>http://www.protocolostomy.com/2010/12/16/good-things-come-in-threes-python-cookbook-third-edition/</link>
		<comments>http://www.protocolostomy.com/2010/12/16/good-things-come-in-threes-python-cookbook-third-edition/#comments</comments>
		<pubDate>Thu, 16 Dec 2010 15:15:03 +0000</pubDate>
		<dc:creator>bkjones</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Sysadmin]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.protocolostomy.com/?p=876</guid>
		<description><![CDATA[It became official earlier today that David Beazley and myself will be co-editing/co-curating the next edition (the Third Edition) of the Python Cookbook. That&#8217;s really exciting. Here&#8217;s why: It&#8217;s Python 3, Cover to Cover Go big or go home. The third edition will be a Python 3 Cookbook. This by itself makes this a rather [...]]]></description>
			<content:encoded><![CDATA[<p>It became official earlier today that David Beazley and myself will be co-editing/co-curating the next edition (the Third Edition) of the Python Cookbook. That&#8217;s really exciting. Here&#8217;s why:</p>
<h3>It&#8217;s Python <span style="color: #de2074;">3</span>, Cover to Cover</h3>
<p>Go big or go home. The third edition will be a Python 3 Cookbook. This by itself makes this a rather large undertaking, since it means modules used in earlier editions that don&#8217;t work in Python 3 can&#8217;t be used, and so those old recipes will need to be scrapped or rewritten.</p>
<p>You heard it right: if a module used in the last edition of Python Cookbook doesn&#8217;t work in Python 3, it won&#8217;t be in this edition. This includes some modules for which several recipes already exist, like dateutil and wxPython, and other modules I would&#8217;ve liked to use for illustrative purposes, like Tornado and psycopg2. I guess there&#8217;s still some time for smaller modules to port to Python 3 and be left alone in this edition, but I don&#8217;t know how realistic that is for something like wxPython.</p>
<p>It&#8217;s going to be ok.</p>
<p>I can&#8217;t find any modules (yet) in the second edition for which Python 3-compatible substitutes don&#8217;t exist, and in some cases I found myself wondering why a separate module was used at all when what needs doing isn&#8217;t a whole lot of work in pure Python anyway. I guess if the module is there and stable, why not use it, eh? Fair enough.</p>
<h3><em><span style="color: #de2074;">Three</span></em> Authors?</h3>
<p>Actually, yes. David, myself, and YOU, where YOU is anyone who posts good Python 3 recipes to the ActiveState &#8216;Python Cookbook&#8217; site. This is actually not new. If you look at the last edition, you&#8217;ll see separate credits for each recipe. The Python Cookbook has always been a community effort, featuring recipes by some very familiar names in the Python community.</p>
<p>Anyway, just in case that wasn&#8217;t direct enough:</p>
<p><a href="http://code.activestate.com/recipes/langs/python/" target="_blank">Go to the ActiveState Python Cookbook site and post a Python 3 recipe, and if it&#8217;s solid, your name and recipe may well be in the book. </a></p>
<p>Basically, ActiveState gives us free reign over their Python Cookbook content, so it&#8217;s a convenient way to let the community contribute to the work. If it&#8217;s in there, and it&#8217;s good, we can use it. They&#8217;re cool like that.</p>
<h3><span style="color: #de2074;">Three</span> Questions</h3>
<p>Answer these in the comments, or send email to Dave and I at PythonCookbook at oreilly.</p>
<ol>
<li>What are your <span style="color: #de2074;">three</span> favorite recipes from either the 1st or 2nd edition?</li>
<li>What are your <span style="color: #de2074;">three</span> <em>least</em> favorite recipes from either the 1st or 2nd edition?</li>
<li>What are <span style="color: #de2074;">three</span> things (techniques, modules, basic tasks) you&#8217;d like to see covered that weren&#8217;t covered in earlier editions?</li>
</ol>
<h3><span style="color: #de2074;">Three</span> Cool Things About the Third Edition</h3>
<ol>
<li>Tests. When the book comes out, we&#8217;ll make the unit tests for the recipes available in some form that is yet to be determined (but they&#8217;ll be available).</li>
<li>Porting help. We&#8217;re not going to leave module authors out in the cold. We&#8217;re going to provide some help/advice. We&#8217;ve both written code in Python 3, and dealt with the issues that arise. I&#8217;m still porting one of my projects and have another in line after that, so I&#8217;ll be dealing with it even more.</li>
<li>Dave and I are both overwhelmed with excitement about this book, about Python 3, and about working with you on it. Come help us out by posting Python 3 recipes (tests are also nice, but not required) on <a href="http://code.activestate.com/recipes/langs/python/">ActiveState</a>, and shoot us an email at PythonCookbook at oreilly dotcom.</li>
</ol>
<p>There will be other cool things, too. We&#8217;ll let you know, so stay tuned to this blog, Dave&#8217;s blog, and you should definitely follow <a href="http://twitter.com/#!/bkjones">@bkjones</a> and <a href="http://twitter.com/#!/dabeaz">@dabeaz</a> on Twitter, since we&#8217;ll be asking for opinions/resources/thoughts on things as we go.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.protocolostomy.com/2010/12/16/good-things-come-in-threes-python-cookbook-third-edition/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

