<?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"
	>

<channel>
	<title>Labix Blog &#187; Python</title>
	<atom:link href="http://blog.labix.org/tag/python/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.labix.org</link>
	<description>by Gustavo Niemeyer</description>
	<pubDate>Fri, 15 Aug 2008 00:24:50 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>Wiki + Spreadsheet</title>
		<link>http://blog.labix.org/2008/08/12/wiki-spreadsheet</link>
		<comments>http://blog.labix.org/2008/08/12/wiki-spreadsheet#comments</comments>
		<pubDate>Tue, 12 Aug 2008 07:46:17 +0000</pubDate>
		<dc:creator>Gustavo Niemeyer</dc:creator>
		
		<category><![CDATA[Math]]></category>

		<category><![CDATA[Project]]></category>

		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://blog.labix.org/?p=96</guid>
		<description><![CDATA[The underlying concept is very simple: spreadsheets are a way to organize text, numbers and formulas into what might be seen as a natively numeric environment: a matrix.  So what would happen if we loosed some of the bolts of the numeric-oriented organization, and tried to reuse the same concepts into a more formatting-oriented [...]]]></description>
			<content:encoded><![CDATA[<p>The underlying concept is very simple: spreadsheets are a way to organize text, numbers and formulas into what might be seen as a natively numeric environment: a matrix.  So what would happen if we loosed some of the bolts of the numeric-oriented organization, and tried to reuse the same concepts into a more formatting-oriented environment which is naturally collaborative: a wiki.</p>
<p>While I do encourage you to answer this with some fantastic new online service (please provide me with an account and the best e-book reader device available once you&#8217;re rich) I had a try at answering this question myself a while ago by writing <a href="http://labix.org/calc" >the Calc macro for Moin</a>.</p>
<p>Basically, the Calc macro allows extracting values found in a wiki page into lists (think columns or rows), and applying formulas and further formatting as wanted.</p>
<p>I believe there&#8217;s a lot of potential on the basic concept, and the prototype, even though functional and useful, surely has a lot to evolve, so I&#8217;ve <a href="https://launchpad.net/moin-calc" onclick="javascript:pageTracker._trackPageview('/outbound/article/https://launchpad.net/moin-calc');">published the project in Launchpad</a> to make contributions easier. I actually apologize for not publishing it earlier.  There was hope that more features would be implemented before releasing, but now it&#8217;s clear that it won&#8217;t get many improvements from me anytime soon. If you do decide to improve it, please try to prepare patches which are mostly ready for integration, including full testing, since I can&#8217;t dedicate much time for it myself in the foreseeable future.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.labix.org/2008/08/12/wiki-spreadsheet/feed</wfw:commentRss>
		</item>
		<item>
		<title>Watch out for list(dict.keys()) in Python 3</title>
		<link>http://blog.labix.org/2008/06/27/watch-out-for-listdictkeys-in-python-3</link>
		<comments>http://blog.labix.org/2008/06/27/watch-out-for-listdictkeys-in-python-3#comments</comments>
		<pubDate>Fri, 27 Jun 2008 21:57:20 +0000</pubDate>
		<dc:creator>Gustavo Niemeyer</dc:creator>
		
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://blog.labix.org/?p=94</guid>
		<description><![CDATA[As everyone is probably aware by now, in Python 3 dict.keys(), dict.values() and dict.items() will all return iterable views instead of lists.  The standard way being suggested to overcome the difference, when the original behavior was actually intended, is to simply use list(dict.keys()).  This should be usually fine, but not in all cases.
One [...]]]></description>
			<content:encoded><![CDATA[<p>As everyone is probably aware by now, in Python 3 dict.keys(), dict.values() and dict.items() will all return iterable <em>views</em> instead of lists.  The standard way <a href="http://www.python.org/dev/peps/pep-3106/" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://www.python.org/dev/peps/pep-3106/');">being suggested</a> to overcome the difference, when the original behavior was actually intended, is to simply use <code>list(dict.keys())</code>.  This should be usually fine, but not in all cases.</p>
<p>One of the reasons why someone might actually <em>opt</em> to perform a more expensive copying operation is because, with the pre-3.0 semantics, the <code>keys()</code> method is <em>atomic</em>, in the sense that the whole operation of converting all dictionary keys to a list is done while the global interpreter lock is held.  Thus, it&#8217;s thread-safe to run <code>dict.keys()</code> with Python 2.X.</p>
<p>The suggested replacement in Python 3, <code>list(dict.keys())</code>, is not.  There&#8217;s a chance that the interpreter will give another thread a chance to run before or during the iteration of the view, and this will cause an exception if the dictionary is modified at the same time.  To fix the problem, either a lock must protect the iteration, or a more expensive operation such as <code>dict.copy().keys()</code> must be used.</p>
<p>The 2to3 tool won&#8217;t help you there, unfortunately.  So, keep an eye on it!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.labix.org/2008/06/27/watch-out-for-listdictkeys-in-python-3/feed</wfw:commentRss>
		</item>
		<item>
		<title>Google using Geohash</title>
		<link>http://blog.labix.org/2008/05/20/google-using-geohash</link>
		<comments>http://blog.labix.org/2008/05/20/google-using-geohash#comments</comments>
		<pubDate>Wed, 21 May 2008 01:54:15 +0000</pubDate>
		<dc:creator>Gustavo Niemeyer</dc:creator>
		
		<category><![CDATA[Project]]></category>

		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://blog.labix.org/2008/05/20/google-using-geohash/</guid>
		<description><![CDATA[According to Dave Troy, Google seems to be using the Geohash algorithm:

Google is employing the GeoHash algorithm I’ve been pushing to do spatial searching using BigTable.  Since database schemes like BigTable don’t support traditional GIS extensions/spatial indexes, GeoHash allows for a simple bounding box search using truncated GeoHash substrings.  I will post separately [...]]]></description>
			<content:encoded><![CDATA[<p>According to Dave Troy, <a href="http://www.openlocation.org/?p=9" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://www.openlocation.org/?p=9');">Google seems to be using</a> the <a href="http://en.wikipedia.org/Geohash" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://en.wikipedia.org/Geohash');">Geohash algorithm</a>:</p>
<blockquote><p>
Google is employing the GeoHash algorithm I’ve been pushing to do spatial searching using BigTable.  Since database schemes like BigTable don’t support traditional GIS extensions/spatial indexes, GeoHash allows for a simple bounding box search using truncated GeoHash substrings.  I will post separately about this shortly, as I am working on some GeoHash tools to expand this functionality.  This is of particular interest to AppEngine developers.
</p></blockquote>
<p>Nice!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.labix.org/2008/05/20/google-using-geohash/feed</wfw:commentRss>
		</item>
		<item>
		<title>dateutil 1.4 is out</title>
		<link>http://blog.labix.org/2008/03/03/dateutil-14-is-out</link>
		<comments>http://blog.labix.org/2008/03/03/dateutil-14-is-out#comments</comments>
		<pubDate>Mon, 03 Mar 2008 03:49:08 +0000</pubDate>
		<dc:creator>Gustavo Niemeyer</dc:creator>
		
		<category><![CDATA[Project]]></category>

		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://blog.labix.org/2008/03/03/dateutil-14-is-out/</guid>
		<description><![CDATA[Friday I&#8217;ve released version 1.4 of dateutil.  There are some interesting fixes there, so please upgrade if you have the chance.
]]></description>
			<content:encoded><![CDATA[<p>Friday I&#8217;ve <a href="http://mail.python.org/pipermail/python-announce-list/2008-February/006455.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://mail.python.org/pipermail/python-announce-list/2008-February/006455.html');">released</a> version 1.4 of <a href="http://labix.org/python-dateutil" >dateutil</a>.  There are some interesting fixes there, so please upgrade if you have the chance.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.labix.org/2008/03/03/dateutil-14-is-out/feed</wfw:commentRss>
		</item>
		<item>
		<title>Enhancements on geohash.org</title>
		<link>http://blog.labix.org/2008/03/01/enhancements-on-geohashorg</link>
		<comments>http://blog.labix.org/2008/03/01/enhancements-on-geohashorg#comments</comments>
		<pubDate>Sat, 01 Mar 2008 21:27:21 +0000</pubDate>
		<dc:creator>Gustavo Niemeyer</dc:creator>
		
		<category><![CDATA[GPS]]></category>

		<category><![CDATA[Project]]></category>

		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://blog.labix.org/2008/03/01/enhancements-on-geohashorg/</guid>
		<description><![CDATA[Some improvements to geohash.org were made.  Some of them were
motivated by a conversation with Rodrigo Stulzer.

Support for geocoding addresses (city names, whatever).  E.g. http://geohash.org/?q=21&#160;Millbank,&#160;London
Support for moving the Geohash marker in the embedded map, so that modifying the position visually is easier.
Support for providing a &#8220;name&#8221; to Geohashes, by appending a colon and the [...]]]></description>
			<content:encoded><![CDATA[<p>Some improvements to <a href="geohash.org">geohash.org</a> were made.  Some of them were<br />
motivated by a conversation with <a href="http://stulzer.net" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://stulzer.net');">Rodrigo Stulzer</a>.</p>
<ul>
<li>Support for geocoding addresses (city names, whatever).  E.g. <a href="http://geohash.org/?q=21%20Millbank,%20London" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://geohash.org/?q=21%20Millbank,%20London');">http://geohash.org/?q=21&nbsp;Millbank,&nbsp;London</a></li>
<li>Support for moving the Geohash marker in the embedded map, so that modifying the position visually is easier.</li>
<li>Support for providing a &#8220;name&#8221; to Geohashes, by appending a colon and the name, in a nice format. E.g. <a href="http://geohash.org/c216ne:Mt_Hood" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://geohash.org/c216ne:Mt_Hood');">http://geohash.org/c216ne:Mt_Hood</a></li>
<li>Provided a <a href="http://geohash.org/site/tips.html#gmaps" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://geohash.org/site/tips.html#gmaps');">bookmark</a> to get a Geohash while <b>in</b> Google Maps.</li>
<li>Provided a <a href="http://geohash.org/site/tips.html#gmaps" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://geohash.org/site/tips.html#gmaps');">Google Maps Mapplet</a>.  When enabled, it adds a Geohash marker identifying the Geohash position in Google Maps, and it may be moved around.  Here is a screenshot:</li>
</ul>
<div style="text-align: center;"><img style="border: 1px solid #9999ff" src="http://geohash.org/static/mapplet.png" /></div>
<p>Check out the <a href="http://geohash.org/site/tips.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://geohash.org/site/tips.html');">Tips &amp; Tricks</a> page for details on these features.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.labix.org/2008/03/01/enhancements-on-geohashorg/feed</wfw:commentRss>
		</item>
		<item>
		<title>geohash.org is public!</title>
		<link>http://blog.labix.org/2008/02/26/geohashorg-is-public</link>
		<comments>http://blog.labix.org/2008/02/26/geohashorg-is-public#comments</comments>
		<pubDate>Wed, 27 Feb 2008 00:11:38 +0000</pubDate>
		<dc:creator>Gustavo Niemeyer</dc:creator>
		
		<category><![CDATA[Article]]></category>

		<category><![CDATA[GPS]]></category>

		<category><![CDATA[Project]]></category>

		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://blog.labix.org/2008/02/26/geohashorg-is-public/</guid>
		<description><![CDATA[After about one year writing this service in my spare time, it&#8217;s finally out.
geohash.org offers short URLs which encode a latitude/longitude pair, so that referencing them in emails, forums, and websites is more convenient.
Geohashes offer properties like arbitrary precision, similar prefixes for nearby positions, and the possibility of gradually removing characters from the end of [...]]]></description>
			<content:encoded><![CDATA[<p>After about one year writing this service in my spare time, it&#8217;s finally out.</p>
<p><a href="http://geohash.org" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://geohash.org');">geohash.org</a> offers short URLs which encode a latitude/longitude pair, so that referencing them in emails, forums, and websites is more convenient.</p>
<p>Geohashes offer properties like arbitrary precision, similar prefixes for nearby positions, and the possibility of gradually removing characters from the end of the code to reduce its size (and gradually lose precision).  I&#8217;ve put the algorithm created in the <b>public domain</b>.  Some details may be seen in the <a href="http://en.wikipedia.org/wiki/Geohash" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://en.wikipedia.org/wiki/Geohash');">Wikipedia article</a> about it (hopefully that&#8217;ll help establishing prior art, and prevent Microsoft from <a href="http://www.freepatentsonline.com/20050023524.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://www.freepatentsonline.com/20050023524.html');">patenting it</a>).</p>
<p>To obtain the Geohash, the user provides latitude and longitude coordinates in a single input box (most commonly used formats for latitude and longitude pairs are accepted), and performs the request.</p>
<p>Besides showing the latitude and longitude corresponding to the given Geohash, users who navigate to a Geohash at geohash.org are also presented with an embedded map, and may download a GPX file, or transfer the waypoint directly to certain GPS receivers. Links are also provided to external sites that may provide further details around the specified location.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.labix.org/2008/02/26/geohashorg-is-public/feed</wfw:commentRss>
		</item>
		<item>
		<title>Mocker 0.10 and trivial patch-mocking of existing objects</title>
		<link>http://blog.labix.org/2007/12/09/mocker-010-and-trivial-patch-mocking-of-existing-objects</link>
		<comments>http://blog.labix.org/2007/12/09/mocker-010-and-trivial-patch-mocking-of-existing-objects#comments</comments>
		<pubDate>Sun, 09 Dec 2007 23:07:13 +0000</pubDate>
		<dc:creator>Gustavo Niemeyer</dc:creator>
		
		<category><![CDATA[Project]]></category>

		<category><![CDATA[Python]]></category>

		<category><![CDATA[Snippet]]></category>

		<category><![CDATA[Test]]></category>

		<guid isPermaLink="false">http://blog.labix.org/2007/12/09/mocker-010-and-trivial-patch-mocking-of-existing-objects/</guid>
		<description><![CDATA[Mocker 0.10 is out, with a number of improvements!
While we&#8217;re talking about Mocker, here is another interesting use case, exploring a pretty unique feature it offers.
Suppose we want to test that a method hello() on an object will call self.show(&#8221;Hello world!&#8221;) at some point.  Let&#8217;s say that the code we want to test is [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://labix.org/mocker" >Mocker</a> 0.10 is out, with a <a href="https://launchpad.net/mocker/trunk/0.10" onclick="javascript:pageTracker._trackPageview('/outbound/article/https://launchpad.net/mocker/trunk/0.10');">number of improvements</a>!</p>
<p>While we&#8217;re talking about Mocker, here is another interesting use case, exploring a pretty unique feature it offers.</p>
<p>Suppose we want to test that a method <i>hello()</i> on an object will call <i>self.show(&#8221;Hello world!&#8221;)</i> at some point.  Let&#8217;s say that the code we want to test is this:</p>
<pre>
 class Greeting(object):

     def show(self, sentence):
         print sentence

     def hello(self):
         self.show("Hello world!")
</pre>
<p>This is the <i>entire</i> test method:</p>
<pre>
def test_hello(self):
    # Define expectation.
    mock = self.mocker.patch(Greeting)
    mock.show("Hello world!")
    self.mocker.replay()

    # Rock on!
    Greeting().hello()
</pre>
<p>This has helped me in practice a few times already, when testing some involved situations.</p>
<p>Note that you can also <i>passthrough</i> the call.  In other words, the call may actually be made on the real method, and mocker will just assert that the call was really made, whatever the effect is.</p>
<p>One more important point: mocker ensures that the real method <i>exists</i> in the real object, and has a specification compatible with the call made.  If it doesn&#8217;t, and assertion error is raised in the test with a nice error message.</p>
<p><b>UPDATE:</b> <i>The method for doing this is actually mocker.patch() rather than mocker.mock(), as documented. Apologies.</i></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.labix.org/2007/12/09/mocker-010-and-trivial-patch-mocking-of-existing-objects/feed</wfw:commentRss>
		</item>
		<item>
		<title>Partial stubbing of os.path.isfile() with Mocker</title>
		<link>http://blog.labix.org/2007/11/22/partial-stubbing-of-ospathisfile-with-mocker</link>
		<comments>http://blog.labix.org/2007/11/22/partial-stubbing-of-ospathisfile-with-mocker#comments</comments>
		<pubDate>Thu, 22 Nov 2007 23:27:14 +0000</pubDate>
		<dc:creator>Gustavo Niemeyer</dc:creator>
		
		<category><![CDATA[Project]]></category>

		<category><![CDATA[Python]]></category>

		<category><![CDATA[Snippet]]></category>

		<category><![CDATA[Test]]></category>

		<guid isPermaLink="false">http://blog.labix.org/2007/11/22/partial-stubbing-of-ospathisfile-with-mocker/</guid>
		<description><![CDATA[One neat feature which Mocker offers is the ability to very easily implement custom behavior on specific functions or methods.
Take for instance the case where you want to pretend to some code that a given file exists, but you don&#8217;t want to get on the way of everything else which needs the same function: 

>>> [...]]]></description>
			<content:encoded><![CDATA[<p>One neat feature which Mocker offers is the ability to very easily implement custom behavior on specific functions or methods.</p>
<p>Take for instance the case where you want to pretend to some code that a given file exists, but you don&#8217;t want to get on the way of everything else which needs the same function: </p>
<pre>
>>> from mocker import *
>>> mocker = Mocker()
>>> isfile = mocker.replace("os.path.isfile", count=False)
>>> _ = expect(isfile("/non/existent")).result(True)
>>> _ = expect(isfile(ANY)).passthrough()

>>> mocker.replay()

>>> import os
>>> os.path.isfile("/non/existent")
True
>>> os.path.isfile("/etc/passwd")
True
>>> os.path.isfile("/other")
False

>>> mocker.restore()

>>> os.path.isfile("/non/existent")
False
</pre>
<p>Notice that the <i>count=False</i> parameter is available in version 0.9.2.  Without it Mocker will act in a more <i>mocking-strict</i> way and enforce that the given expressions should be executed precisely the given number of times (which defaults to one, and may be modified with the <i>count()</i> method). </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.labix.org/2007/11/22/partial-stubbing-of-ospathisfile-with-mocker/feed</wfw:commentRss>
		</item>
		<item>
		<title>More releases: dateutil 1.3 and nicefloat 1.1</title>
		<link>http://blog.labix.org/2007/11/19/more-releases-dateutil-13-and-nicefloat-11</link>
		<comments>http://blog.labix.org/2007/11/19/more-releases-dateutil-13-and-nicefloat-11#comments</comments>
		<pubDate>Mon, 19 Nov 2007 22:24:33 +0000</pubDate>
		<dc:creator>Gustavo Niemeyer</dc:creator>
		
		<category><![CDATA[Project]]></category>

		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://blog.labix.org/2007/11/19/more-releases-dateutil-13-and-nicefloat-11/</guid>
		<description><![CDATA[A couple of additional releases tonight: dateutil 1.3, and nicefloat 1.1.
They&#8217;re both bug fixing releases.
]]></description>
			<content:encoded><![CDATA[<p>A couple of additional releases tonight: <a href="http://labix.org/python-dateutil" >dateutil 1.3</a>, and <a href="http://labix.org/python-nicefloat" >nicefloat 1.1</a>.</p>
<p>They&#8217;re both bug fixing releases.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.labix.org/2007/11/19/more-releases-dateutil-13-and-nicefloat-11/feed</wfw:commentRss>
		</item>
		<item>
		<title>Mocker 0.9</title>
		<link>http://blog.labix.org/2007/11/17/mocker-09</link>
		<comments>http://blog.labix.org/2007/11/17/mocker-09#comments</comments>
		<pubDate>Sat, 17 Nov 2007 21:01:49 +0000</pubDate>
		<dc:creator>Gustavo Niemeyer</dc:creator>
		
		<category><![CDATA[Project]]></category>

		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://blog.labix.org/2007/11/17/mocker-09/</guid>
		<description><![CDATA[A few more improvements were made to Mocker.
]]></description>
			<content:encoded><![CDATA[<p>A few more <a href="http://codebrowse.launchpad.net/~niemeyer/mocker/trunk/annotate/?file_id=news-20071112015353-3p0wa0n8cx1s5crs-1" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://codebrowse.launchpad.net/~niemeyer/mocker/trunk/annotate/?file_id=news-20071112015353-3p0wa0n8cx1s5crs-1');">improvements</a> were made to <a href="http://labix.org/mocker" >Mocker</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.labix.org/2007/11/17/mocker-09/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
