<?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>In Nomine - The Lotus Land &#187; Python</title>
	<atom:link href="http://www.in-nomine.org/category/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.in-nomine.org</link>
	<description>The focused mind can pierce through stone...</description>
	<lastBuildDate>Sat, 19 Jun 2010 17:59:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>docutils: ImportError: No module named roman</title>
		<link>http://www.in-nomine.org/2009/04/07/docutils-importerror-no-module-named-roman/</link>
		<comments>http://www.in-nomine.org/2009/04/07/docutils-importerror-no-module-named-roman/#comments</comments>
		<pubDate>Tue, 07 Apr 2009 08:22:14 +0000</pubDate>
		<dc:creator>asmodai</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[docutils]]></category>

		<guid isPermaLink="false">http://www.in-nomine.org/?p=278</guid>
		<description><![CDATA[For some reason setup.py can fail with docutils complaining it cannot find the roman module. One thing that works is just removing docutils from your site-packages and reinstall it.]]></description>
			<content:encoded><![CDATA[<p>For some reason setup.py can fail with docutils complaining it cannot find the roman module. One thing that works is just removing docutils from your site-packages and reinstall it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.in-nomine.org/2009/04/07/docutils-importerror-no-module-named-roman/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JSONP with Werkzeug</title>
		<link>http://www.in-nomine.org/2009/04/03/jsonp-with-werkzeug/</link>
		<comments>http://www.in-nomine.org/2009/04/03/jsonp-with-werkzeug/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 13:07:15 +0000</pubDate>
		<dc:creator>asmodai</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[jsonp]]></category>
		<category><![CDATA[werkzeug]]></category>

		<guid isPermaLink="false">http://www.in-nomine.org/?p=269</guid>
		<description><![CDATA[So I had implemented a simple JSON data server with Werkzeug for a classroom experiment. Unfortunately in my haste to get everything up and running I totally forgot about the fact that, since we cannot allow uploads to this server of various custom made webpages, using jQuery&#8217;s $.ajax() everything just fails since it will then [...]]]></description>
			<content:encoded><![CDATA[<p>So I had implemented a simple <a title="JSON data format website" href="http://www.json.org/">JSON</a> data server with Werkzeug for a classroom experiment. Unfortunately in my haste to get everything up and running I totally forgot about the fact that, since we cannot allow uploads to this server of various custom made webpages, using <a title="Ajax/jQuery.ajax() documentation" href="http://docs.jquery.com/Ajax/jQuery.ajax">jQuery&#8217;s <code>$.ajax()</code></a> everything just fails since it will then be a cross-site scripting request.</p>
<p>So, normally you would do something like the following in order to return JSON data:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">return</span> json.<span style="color: black;">dumps</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span></pre></div></div>

<p>Which would be used with the $.ajax() call in a way like the following:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;POST&quot;</span><span style="color: #339933;">,</span>
  url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;http://example.com/json/something&quot;</span><span style="color: #339933;">,</span>
  data<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;parameter=value&quot;</span><span style="color: #339933;">,</span>
  dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;json&quot;</span><span style="color: #339933;">,</span>
  error<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>XMLHttpRequest<span style="color: #339933;">,</span> textStatus<span style="color: #339933;">,</span> errorThrown<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #339933;">,</span> msg<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Which is perfectly fine for scripts getting and using the data on the same host/domain. But, as said before, this will fail with warnings similar to: <code>"Access to restricted URI denied" code: "1012" nsresult: "0xdeadc0de (NS_ERROR_DOM_BAD_URI)"</code>.</p>
<p>One way out of this is using <a title="Remote JSON - JSONP" href="http://bob.pythonmac.org/archives/2005/12/05/remote-json-jsonp/">JSONP</a>. jQuery has a <a title="Ajax/jQuery.getJSON() documentation" href="http://docs.jquery.com/Ajax/jQuery.getJSON"><code>$.getJSON()</code> function</a>, which loads JSON data using a HTTP GET request. Now, the simplistic way to convert your code would be to change it as such:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">getJSON</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;http://example.com/json/something&quot;</span><span style="color: #339933;">,</span>
  <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>But this causes another issue. Since <code>$.getJSON()</code> GETs the JSON data, but doesn&#8217;t use eval() on it, but instead pulls the result into <code>script</code> tags, it somehow causes,on Firefox at least, an invalid label error. In order to fix this you need to set up the JSON data server to properly support a callback argument, to use <code>$.getJSON()</code> how it is meant to be used:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">getJSON</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;http://example.com/json/something?jsoncallback=?&quot;</span><span style="color: #339933;">,</span>
  <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In the code above the additional parameter <code>jsoncallback</code> will, thanks to jQuery, get the question mark replaced by an alphanumeric string (typically in the form of <code>jsonp</code> followed by a timestamp). This value should be used to wrap the resulting JSON data with. This means you would have to change the initial Python code to something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">return</span> request.<span style="color: black;">args</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'jsoncallback'</span><span style="color: black;">&#41;</span> + <span style="color: #483d8b;">'('</span> + json.<span style="color: black;">dumps</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">')'</span></pre></div></div>

<p>Of course this causes problems when you want to reuse the code for both AJAX use on the same host/domain and use it from outside. So in order to make both work you can test on whether or not the callback parameter is available and return the appropriate data. I came up with this little snippet for that:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> jsonwrapper<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, request, data<span style="color: black;">&#41;</span>:
    callback = request.<span style="color: black;">args</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'jsoncallback'</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span> callback:
        <span style="color: #ff7700;font-weight:bold;">return</span> callback + <span style="color: #483d8b;">'('</span> + json.<span style="color: black;">dumps</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">')'</span>
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> json.<span style="color: black;">dumps</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.in-nomine.org/2009/04/03/jsonp-with-werkzeug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python 2.6 compiler options results</title>
		<link>http://www.in-nomine.org/2008/04/12/python-26-compiler-options-results/</link>
		<comments>http://www.in-nomine.org/2008/04/12/python-26-compiler-options-results/#comments</comments>
		<pubDate>Sat, 12 Apr 2008 17:10:56 +0000</pubDate>
		<dc:creator>asmodai</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[edward tufte]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[python 2.6]]></category>

		<guid isPermaLink="false">http://www.in-nomine.org/?p=227</guid>
		<description><![CDATA[So after yesterday&#8217;s post about some compiler results with Python 2.6 I wanted to show how some of GCC&#8217;s architecture-specific compiler flags affect the execution of pybench. As I explained in comments I think most people will never even touch the flags passed to Python&#8217;s build. Nonetheless, some people asked if I had tuned it [...]]]></description>
			<content:encoded><![CDATA[<p>So after yesterday&#8217;s post about some compiler results with Python 2.6 I wanted to show how some of GCC&#8217;s architecture-specific compiler flags affect the execution of pybench. As I explained in comments I think most people will never even touch the flags passed to Python&#8217;s build. Nonetheless, some people asked if I had tuned it in any way. <a title="Pádraig Brady's homepage" href="http://www.pixelbeat.org/">Pádraig Brady</a> <a href="http://www.in-nomine.org/2008/04/11/python-26a2-execution-times-with-various-compilers/#comment-3813">had asked me</a> if I had used the optimal GCC architecture flags. On my FreeBSD 7.0-STABLE machine at home (AMD Athlon(tm) 64 X2 Dual Core Processor 4600+ (2411.13-MHz K8-class CPU)) <a title="GCC CPU opt script" href="http://www.pixelbeat.org/scripts/gcccpuopt">his script</a> stated I had to pass along &#8220;-m32 -march=k8 -mfpmath=sse&#8221;. My machine is fully 64 bits so I left out the -m32 (since it will not link anyway) and used &#8220;-march=k8 -mfpmath=sse&#8221; (using -march=native instead of k8 resulted in a 0,1 seconds faster result and -mtune=native -march=native instead of k8 resulted in a 0,1 &#8211; 0,2 seconds faster result).</p>
<p>The default option flags are on my system: -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes.</p>
<p>Considering some other comments about how I did not use a 0-origin for my y-axis I have to point out two things: firstly, given the sometimes close results zooming out too much can eliminate detailed information (of course you have to be careful not to zoom in too much as well); secondly, I like to make sure the graph itself is appropriately centered so you do not get a whitespace skewing in the resulting image. I think, being a follower of the <a title="Edward Tufte's homepage" href="http://www.edwardtufte.com/">Edward Tufte</a> school of graphic displaying, I did reasonably well. The graphs were made with a tool called <a title="Ploticus homepage" href="http://ploticus.sourceforge.net/">Ploticus</a>.</p>
<p><a href="http://www.in-nomine.org/wp-content/uploads/2008/04/gcc421def-march.png"><img class="aligncenter size-full wp-image-228" style="vertical-align: middle;" title="gcc421def-march" src="http://www.in-nomine.org/wp-content/uploads/2008/04/gcc421def-march.png" alt="GCC 4.2.1 default and architecture options" width="557" height="357" /></a></p>
<p>I was curious how the optimization level influenced the resulting program and as such I removed the -O3 option from the compiler flags. As is evident from the graph you are looking at a bit more than a doubling of execution time (an average of 14,2 seconds versus the previous 6,6 and 6,5 seconds).</p>
<p><a href="http://www.in-nomine.org/wp-content/uploads/2008/04/gcc421def-march-noo3.png"><img class="aligncenter size-full wp-image-229" style="vertical-align: middle;" title="gcc421def-march-noo3" src="http://www.in-nomine.org/wp-content/uploads/2008/04/gcc421def-march-noo3.png" alt="GCC 4.2.1 with no O3" width="557" height="374" /></a></p>
<p>So, given the huge performance hit by merely leaving out the -O3, I was interested how the other optimization levels worked out. <a href="http://www.in-nomine.org/2008/04/11/python-26a2-execution-times-with-various-compilers/#comment-3820">Holger Hoffstätte asked to use -O2 -fomit-frame-pointer</a> instead of -O3. Basically the results of -O3 (average of 6,5 seconds) and -O2 -fomit-frame-pointer (average of 6,5 seconds) were equal. The result of using -O1 (I could not really discern much of a speed difference by adding -fomit-frame-pointer, also for the -O2 case it was still an average of 6,5 seconds) was quite interesting. It already improves execution by ~86%. From -O1 to -O2/-O3 we are looking at another increase of ~16%. From the no optimization case to -O2/-O3 execution improves by ~118%</p>
<p><a href="http://www.in-nomine.org/wp-content/uploads/2008/04/gcc421options.png"><img class="aligncenter size-full wp-image-230" style="vertical-align: middle;" title="gcc421options" src="http://www.in-nomine.org/wp-content/uploads/2008/04/gcc421options.png" alt="GCC 4.2.1 with various options" width="557" height="391" /></a></p>
<p>I tried a profile-guided optimization build, but I have some issues on my FreeBSD 7.0-STABLE with libgcov. Apparently only a libgconv.a is provided and linking gives me a relocation warning. Thankfully I also had a GCC 4.2.4 snapshot from March installed and did a PGO build, but I managed to only shave of about 0,2 seconds on the average time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.in-nomine.org/2008/04/12/python-26-compiler-options-results/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Python 2.6a2 execution times with various compilers</title>
		<link>http://www.in-nomine.org/2008/04/11/python-26a2-execution-times-with-various-compilers/</link>
		<comments>http://www.in-nomine.org/2008/04/11/python-26a2-execution-times-with-various-compilers/#comments</comments>
		<pubDate>Fri, 11 Apr 2008 14:43:54 +0000</pubDate>
		<dc:creator>asmodai</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[compiler]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[icc]]></category>
		<category><![CDATA[python 2.6]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://www.in-nomine.org/?p=224</guid>
		<description><![CDATA[Due to recent concerns with memory use and execution speed I was curious how Python would behave with different compilers. I took Python 2.6a2 r62288 from the Subversion repository and compiled it with the flags: &#8211;with-threads &#8211;enable-unicode=ucs4 &#8211;enable-ipv6. The machine is a HP dc7700p with 1GB memory with an Intel Core2 6300 @ 1.86GHz running [...]]]></description>
			<content:encoded><![CDATA[<p>Due to recent concerns with memory use and execution speed I was curious how Python would behave with different compilers. I took Python 2.6a2 r62288 from the Subversion repository and compiled it with the flags: &#8211;with-threads &#8211;enable-unicode=ucs4 &#8211;enable-ipv6. The machine is a HP dc7700p with 1GB memory with an Intel Core2 6300 @ 1.86GHz running Ubuntu 7.10. I installed GCC 3.3.6, 3.4.6, 4.1.3, 4.2.1 from the Gutsy repository, and Intel 10.1.015. The MS Visual Studio 2008 Python was the MSI snapshot of 2008-04-10 from the main Python site. I ran this through Wine 0.9.46 after installing the VC2008 runtime.</p>
<p>First various GCC versions: 3.3.6, 3.4.6, 4.1.3, 4.2.1:</p>
<p><a href="http://www.in-nomine.org/wp-content/uploads/2008/04/python-gcc.png"><img class="aligncenter size-full wp-image-225" title="python-gcc.png" src="http://www.in-nomine.org/wp-content/uploads/2008/04/python-gcc.png" alt="Python 2.6a2 compiled with GCC" width="557" height="391" /></a></p>
<p>It is good to see that the 3.4 series is faster than the 3.3 series and the 4.2 series is faster than the 4.1 series. I am a bit worried about the 4.1 series drop in performance compared to the 3 series though.</p>
<p>Next we have Python compiled with GCC 3.4.6, 4.2.1, Intel CC 10.1.015, MSC from Visual Studio 2008:</p>
<p><a href="http://www.in-nomine.org/wp-content/uploads/2008/04/python-compilers.png"><img class="aligncenter size-full wp-image-226" title="python-compilers" src="http://www.in-nomine.org/wp-content/uploads/2008/04/python-compilers.png" alt="Python 2.6a2 compiled with GCC, ICC, MSC" width="557" height="391" /></a></p>
<p>It is nice to see how the Microsoft Visual Studio 2008 compiler produces a binary that, when run through Wine, still performs quite well compared to GCC. I am not quite sure if Wine incurs a performance penalty or not. What&#8217;s quite impressive is the performance of the Intel CC compiled Python. If we take the fastest GCC, which is 4.2.1 at the moment, take the average of the 10 rounds of execution, which is 6,574 seconds, and compare that to the average of ICC, which is 5,412 seconds, we see that ICC is about 21% faster. If we take the slowest, GCC 4.1.3 with an average of 7,002 seconds, we even get a result that ICC is about 29% faster.</p>
<p>So it seems for people who want to get the full performance out of Python compiling with ICC might be quite beneficial. I want to check out how ICC progressed from version 8 to version 10 performance-wise.</p>
<p>The raw data can be found at <a title="Python pybench results" href="http://www.in-nomine.org/~asmodai/python-pybench.txt">http://www.in-nomine.org/~asmodai/python-pybench.txt</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.in-nomine.org/2008/04/11/python-26a2-execution-times-with-various-compilers/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Rangaku getting form</title>
		<link>http://www.in-nomine.org/2008/04/06/rangaku-getting-form/</link>
		<comments>http://www.in-nomine.org/2008/04/06/rangaku-getting-form/#comments</comments>
		<pubDate>Sun, 06 Apr 2008 21:15:47 +0000</pubDate>
		<dc:creator>asmodai</dc:creator>
				<category><![CDATA[Languages]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[dutch]]></category>
		<category><![CDATA[japanese]]></category>
		<category><![CDATA[kanji]]></category>
		<category><![CDATA[kouyou]]></category>
		<category><![CDATA[rangaku]]></category>

		<guid isPermaLink="false">http://www.in-nomine.org/?p=219</guid>
		<description><![CDATA[I spent the past three days doing a lot of coding for my Dutch-Japanese dictionary site Rangaku (or better known as Kouyou). I am happy to see that things are finally starting to pull together now. I had intended to publish things much sooner, but I had a lot of catching up to do on [...]]]></description>
			<content:encoded><![CDATA[<p>I spent the past three days doing a lot of coding for my Dutch-Japanese dictionary site <a title="Kouyou Dutch-Japanese dictionary" href="http://www.rangaku.org/">Rangaku (or better known as Kouyou)</a>. I am happy to see that things are finally starting to pull together now. I had intended to publish things much sooner, but I had a lot of catching up to do on the Python front. Partially thanks to my new job and my own endeavours in my spare time I am mastering Python at least on a level I feel I am reasonably comfortable with it. Of course, the release of various tools like <a title="Werkzeug" href="http://werkzeug.pocoo.org/">Werkzeug</a>, <a title="Genshi" href="http://genshi.edgewall.org/">Genshi</a> or <a title="SQLAlchemy" href="http://www.sqlalchemy.org/">SQLAlchemy</a> helped me a lot as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.in-nomine.org/2008/04/06/rangaku-getting-form/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>2008 will be a stellar year for Python</title>
		<link>http://www.in-nomine.org/2008/02/06/2008-will-be-a-stellar-year-for-python/</link>
		<comments>http://www.in-nomine.org/2008/02/06/2008-will-be-a-stellar-year-for-python/#comments</comments>
		<pubDate>Wed, 06 Feb 2008 20:56:24 +0000</pubDate>
		<dc:creator>asmodai</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[babel]]></category>
		<category><![CDATA[bitten]]></category>
		<category><![CDATA[genshi]]></category>
		<category><![CDATA[trac]]></category>
		<category><![CDATA[webob]]></category>
		<category><![CDATA[werkzeug]]></category>

		<guid isPermaLink="false">http://www.in-nomine.org/2008/02/06/2008-will-be-a-stellar-year-for-python/</guid>
		<description><![CDATA[For the past few months there&#8217;s been a certain vibe building up. This vibe is coming from parts of the Python community. As it stands 2008 seems to become a very stellar year for Python. Just after New Year TIOBE reported this: Python has been declared as programming language of 2007. It was a close [...]]]></description>
			<content:encoded><![CDATA[<p>For the past few months there&#8217;s been a certain vibe building up. This vibe is coming from parts of the Python community. As it stands 2008 seems to become a very stellar year for Python.</p>
<p>Just after New Year <a title="TIOBE Programming Community Index" href="http://www.tiobe.com/index.htm?tiobe_index">TIOBE</a> reported this:</p>
<blockquote><p>Python has been declared as programming language of 2007. It was a close finish, but in the end Python appeared to have the largest increase in ratings in one year time (2.04%). There is no clear reason why Python made this huge jump in 2007. Last month Python surpassed Perl for the first time in history, which is an indication that Python has become the &#8220;de facto&#8221; glue language at system level. It is especially beloved by system administrators and build managers. Chances are high that Python&#8217;s star will rise further in 2008, thanks to the upcoming release of Python 3.</p></blockquote>
<p>There are a lot of really interesting developments going on.  Some interesting developments in my opinion are (in no particular order): <a title="Babel" href="http://babel.edgewall.org/">Babel</a>, <a title="http://bitten.edgewall.org/" href="http://www.in-nomine.org/wp-admin/Bitten">Bitten</a>, <a title="Genshi" href="http://genshi.edgewall.org/">Genshi</a>, <a title="Trac" href="http://trac.edgewall.org/">Trac</a>, <a title="http://werkzeug.pocoo.org/" href="http://www.in-nomine.org/wp-admin/Werkzeug">Werkzeug</a>, <a title="http://pythonpaste.org/webob/" href="http://www.in-nomine.org/wp-admin/WebOb">WebOb</a>.</p>
<p>An exciting year indeed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.in-nomine.org/2008/02/06/2008-will-be-a-stellar-year-for-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Werkzeug 0.1 released &#8211; WSGI toolbox</title>
		<link>http://www.in-nomine.org/2007/12/21/werkzeug-01-released-wsgi-toolbox/</link>
		<comments>http://www.in-nomine.org/2007/12/21/werkzeug-01-released-wsgi-toolbox/#comments</comments>
		<pubDate>Fri, 21 Dec 2007 11:48:26 +0000</pubDate>
		<dc:creator>asmodai</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[cherrypy]]></category>
		<category><![CDATA[werkzeug]]></category>
		<category><![CDATA[wsgi]]></category>

		<guid isPermaLink="false">http://www.in-nomine.org/2007/12/21/werkzeug-01-released-wsgi-toolbox/</guid>
		<description><![CDATA[Armin Ronacher has released Werkzeug 0.1 a little while ago. As the website for Werkzeug says: &#8220;Werkzeug is a collection of various utilities for WSGI applications. It features request and response objects as well as a powerful url dispatcher and a debugging system.&#8221; I have it on my todo list to convert my current CherryPy [...]]]></description>
			<content:encoded><![CDATA[<p>Armin Ronacher has released <a title="Werkzeug 0.1 Released" href="http://lucumr.pocoo.org/cogitations/2007/12/09/werkzeug-01-released/">Werkzeug 0.1 a little while ago</a>. As the <a title="Werkzeug" href="http://werkzeug.pocoo.org/">website for Werkzeug</a> says: &#8220;Werkzeug is a collection of various utilities for WSGI applications. It     features request and response objects as well as a powerful url dispatcher     and a debugging system.&#8221;</p>
<p>I have it on my todo list to convert my current CherryPy environment to Werkzeug as a proof of concept and see which one of the two I prefer and will ultimately use for <a title="The Kouyou Project" href="http://www.rangaku.org/">my Japanese-Dutch dictionary project</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.in-nomine.org/2007/12/21/werkzeug-01-released-wsgi-toolbox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python&#8217;s sys.stdout loses encoding</title>
		<link>http://www.in-nomine.org/2007/12/13/pythons-sysstdout-loses-encoding/</link>
		<comments>http://www.in-nomine.org/2007/12/13/pythons-sysstdout-loses-encoding/#comments</comments>
		<pubDate>Thu, 13 Dec 2007 14:45:26 +0000</pubDate>
		<dc:creator>asmodai</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[unicode]]></category>

		<guid isPermaLink="false">http://www.in-nomine.org/2007/12/13/pythons-sysstdout-loses-encoding/</guid>
		<description><![CDATA[When you use Python with sys.stdout you might run into a problem where sys.stdout.encoding suddenly becomes None. This happens due to the fact that upon using a pipe or redirection, at least under Unix, it falls back to not knowing anything about the target. In order to work around this you can add a fallback [...]]]></description>
			<content:encoded><![CDATA[<p>When you use Python with sys.stdout you might run into a problem where sys.stdout.encoding suddenly becomes None. This happens due to the fact that upon using a pipe or redirection, at least under Unix, it falls back to not knowing anything about the target. In order to work around this you can add a fallback to use locale.getpreferredencoding(). So if you use encode() on a string you can do something like:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">locale</span> <span style="color: #ff7700;font-weight:bold;">import</span> getpreferredencoding
&nbsp;
text = u<span style="color: #483d8b;">&quot;Something special&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span> text.<span style="color: black;">encode</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">stdout</span>.<span style="color: black;">encoding</span> <span style="color: #ff7700;font-weight:bold;">or</span> getpreferredencoding<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">or</span> <span style="color: #483d8b;">'ascii'</span>, <span style="color: #483d8b;">'replace'</span><span style="color: black;">&#41;</span></pre></div></div>

<p>This is how we currently use it within <a href="http://babel.edgewall.org/">Babel</a> as well for printing the locale list.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.in-nomine.org/2007/12/13/pythons-sysstdout-loses-encoding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQLAlchemy and simple WHERE clauses using AND</title>
		<link>http://www.in-nomine.org/2007/11/23/sqlalchemy-and-simple-where-clauses-using-and/</link>
		<comments>http://www.in-nomine.org/2007/11/23/sqlalchemy-and-simple-where-clauses-using-and/#comments</comments>
		<pubDate>Fri, 23 Nov 2007 10:17:06 +0000</pubDate>
		<dc:creator>asmodai</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sqlalchemy]]></category>
		<category><![CDATA[trac]]></category>

		<guid isPermaLink="false">http://www.in-nomine.org/2007/11/23/sqlalchemy-and-simple-where-clauses-using-and/</guid>
		<description><![CDATA[These posts use code from the Trac project. I&#8217;m using the question mark notation for in-place variable substitution, this is where you normally use either direct variables or an indirection mechanism. If you have done SQL before you are familiar with the syntax such as: SELECT name FROM auth_cookie WHERE cookie = ? AND ipnr [...]]]></description>
			<content:encoded><![CDATA[<p>These posts use code from the <a href="http://trac.edgewall.org/">Trac</a> project. I&#8217;m using the question mark notation for in-place variable substitution, this is where you normally use either direct variables or an indirection mechanism.</p>
<p>If you have done SQL before you are familiar with the syntax such as:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> name <span style="color: #993333; font-weight: bold;">FROM</span> auth_cookie <span style="color: #993333; font-weight: bold;">WHERE</span> cookie <span style="color: #66cc66;">=</span> ? <span style="color: #993333; font-weight: bold;">AND</span> ipnr <span style="color: #66cc66;">=</span> ?;</pre></div></div>

<p>So, how does one do this with <a href="http://www.sqlalchemy.org/">SQLAlchemy</a>?</p>
<p>With SQLAlchemy (SA in short) you first declare a schema within Python:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">auth_cookie = Table<span style="color: black;">&#40;</span><span style="color: #483d8b;">'auth_cookie'</span>, metadata,
        Column<span style="color: black;">&#40;</span><span style="color: #483d8b;">'cookie'</span>, String, primary_key=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>,
        Column<span style="color: black;">&#40;</span><span style="color: #483d8b;">'name'</span>, String, primary_key=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>,
        Column<span style="color: black;">&#40;</span><span style="color: #483d8b;">'ipnr'</span>, String, primary_key=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>,
        Column<span style="color: black;">&#40;</span><span style="color: #483d8b;">'time'</span>, Integer<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Next you import this schema (living within Trac as trac/db/schema.py) as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> trac.<span style="color: black;">db</span>.<span style="color: black;">schema</span> <span style="color: #ff7700;font-weight:bold;">import</span> auth_cookie</pre></div></div>

<p>This allows direct manipulation using direct calls to auth_cookie. So for a SQL select we need to extend our code as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> sqlalchemy <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">select</span></pre></div></div>

<p>This allows us to build an almost equivalent statement as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">statement = <span style="color: #dc143c;">select</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>auth_cookie.<span style="color: black;">c</span>.<span style="color: black;">name</span><span style="color: black;">&#93;</span>, auth_cookie.<span style="color: black;">c</span>.<span style="color: black;">cookie</span>==<span style="color: #66cc66;">?</span><span style="color: black;">&#41;</span></pre></div></div>

<p>To add the AND clause SA has a very simple function to add into your code:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> sqlalchemy <span style="color: #ff7700;font-weight:bold;">import</span> and_, <span style="color: #dc143c;">select</span></pre></div></div>

<p>This allows us to extend the previous statement as such:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">statement = <span style="color: #dc143c;">select</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>auth_cookie.<span style="color: black;">c</span>.<span style="color: black;">name</span><span style="color: black;">&#93;</span>, and_<span style="color: black;">&#40;</span>auth_cookie.<span style="color: black;">c</span>.<span style="color: black;">cookie</span>==<span style="color: #66cc66;">?</span>, auth_cookie.<span style="color: black;">c</span>.<span style="color: black;">ipnr</span>==<span style="color: #66cc66;">?</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Similarly there&#8217;s an <code>or_()</code> function as well, which works exactly the same.</p>
<p>Now the difficulty arose due to the fact this SQL query changed its WHERE-clause depending on an <code>if/else</code>. The regular case was the first statement we created, the other case added the cookie&#8217;s IP number into the equation. So how to deal with that?</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">statement = <span style="color: #dc143c;">select</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>auth_cookie.<span style="color: black;">c</span>.<span style="color: black;">name</span><span style="color: black;">&#93;</span>, auth_cookie.<span style="color: black;">c</span>.<span style="color: black;">cookie</span>==<span style="color: #66cc66;">?</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">self</span>.<span style="color: black;">check_ip</span>:
    statement.<span style="color: black;">append_whereclause</span><span style="color: black;">&#40;</span>and_<span style="color: black;">&#40;</span>auth_cookie.<span style="color: black;">c</span>.<span style="color: black;">ipnr</span>==<span style="color: #66cc66;">?</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>As you can see, depending on whether or not check_ip is set it changes the statement in-place and expands the WHERE-clause with an AND for ipnr.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.in-nomine.org/2007/11/23/sqlalchemy-and-simple-where-clauses-using-and/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FreeBSD, SQLite, FTS2 and SQLAlchemy</title>
		<link>http://www.in-nomine.org/2007/08/21/freebsd-sqlite-fts2-and-sqlalchemy/</link>
		<comments>http://www.in-nomine.org/2007/08/21/freebsd-sqlite-fts2-and-sqlalchemy/#comments</comments>
		<pubDate>Tue, 21 Aug 2007 08:54:01 +0000</pubDate>
		<dc:creator>asmodai</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Operating Systems]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[sqlalchemy]]></category>
		<category><![CDATA[sqlite]]></category>

		<guid isPermaLink="false">http://www.in-nomine.org/2007/08/21/freebsd-sqlite-fts2-and-sqlalchemy/</guid>
		<description><![CDATA[I was trying to use the SQLite 3.4.1 installed port with Python and SQLAlchemy and the moment I wanted to create a table within the database Python crashed. After a bunch of debugging it turns out that enabling the FTS2 option of the port causes these crashes. The sqlite3Fts2InitHashTable() call is where it fails. I [...]]]></description>
			<content:encoded><![CDATA[<p>I was trying to use the SQLite 3.4.1 installed port with Python and SQLAlchemy and the moment I wanted to create a table within the database Python crashed.</p>
<p>After a bunch of debugging it turns out that enabling the FTS2 option of the port causes these crashes. The sqlite3Fts2InitHashTable() call is where it fails. I notified the port maintainer and in the mean time rebuilt without FTS2.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.in-nomine.org/2007/08/21/freebsd-sqlite-fts2-and-sqlalchemy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
