<?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>( f o o b a r . l u ) &#187; Python</title>
	<atom:link href="http://foobar.lu/wp/category/coding/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://foobar.lu/wp</link>
	<description>coding should be fun</description>
	<lastBuildDate>Wed, 31 Mar 2010 11:39:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Unable to easy_install psycopg2 on debian</title>
		<link>http://foobar.lu/wp/2009/10/29/unable-to-easy_install-psycopg2-on-debian/</link>
		<comments>http://foobar.lu/wp/2009/10/29/unable-to-easy_install-psycopg2-on-debian/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 15:18:30 +0000</pubDate>
		<dc:creator>exhuma.twn</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://foobar.lu/wp/?p=66</guid>
		<description><![CDATA[Problem:
$ easy_install psycopg2
Searching for psycopg2 &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<h3>Problem:</h3>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;width:530px"><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">$ easy_install psycopg2<br />
Searching for psycopg2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Reading http://pypi.python.org/simple/psycopg2/ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
Reading http://initd.org/projects/psycopg2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Reading http://initd.org/pub/software/psycopg/ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Best match: psycopg2 2.0.13 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
Downloading http://initd.org/pub/software/psycopg/psycopg2-2.0.13.tar.gz &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
Processing psycopg2-2.0.13.tar.gz &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
Running psycopg2-2.0.13/setup.py -q bdist_egg --dist-dir /tmp/easy_install-cHE0C_/psycopg2-2.0.13/egg-dist-tmp-x-CxRS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
error: Setup script exited with error: No such file or directory</div></div>
<h3>Solution:</h3>
<p>This most likely indicates that you are missing the &#8220;libpq&#8221; headers:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;width:530px"><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">sudo aptitude install libpq-dev</div></div>
<p>should solve the problem</p>
]]></content:encoded>
			<wfw:commentRss>http://foobar.lu/wp/2009/10/29/unable-to-easy_install-psycopg2-on-debian/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python startup (command completion &amp; history)</title>
		<link>http://foobar.lu/wp/2008/08/21/python-startup-command-completion-history/</link>
		<comments>http://foobar.lu/wp/2008/08/21/python-startup-command-completion-history/#comments</comments>
		<pubDate>Thu, 21 Aug 2008 11:18:17 +0000</pubDate>
		<dc:creator>exhuma.twn</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://foobar.lu/wp/2008/08/21/python-startup-command-completion-history/</guid>
		<description><![CDATA[If you want command completion and a history in your python shell, export the PYTHONSTARTUP env var (export PYTHONSTARTUP=$HOME/.pystartup) in your bashrc and create a file ~/.pystartup with the following contents:
import atexit
import os
import readline
import rlcompleter

historyPath = os.path.expanduser&#40;&#34;~/.pyhistory&#34;&#41;

def save_history&#40;historyPath=historyPath&#41;:
import readline
readline.write_history_file&#40;historyPath&#41;

if os.path.exists&#40;historyPath&#41;:
readline.read_history_file&#40;historyPath&#41;

readline.parse_and_bind&#40;'tab: complete'&#41;

atexit.register&#40;save_history&#41;
del os, atexit, readline, rlcompleter, save_history, historyPath
]]></description>
			<content:encoded><![CDATA[<p>If you want command completion and a history in your python shell, export the <em>PYTHONSTARTUP</em> env var (<em>export PYTHONSTARTUP=$HOME/.pystartup) </em>in your bashrc and create a file ~/.pystartup with the following contents:</p>
<div class="codecolorer-container python twitlight" style="overflow:auto;white-space:nowrap;width:530px"><div class="python codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">import</span> <span class="kw3">atexit</span><br />
<span class="kw1">import</span> <span class="kw3">os</span><br />
<span class="kw1">import</span> <span class="kw3">readline</span><br />
<span class="kw1">import</span> <span class="kw3">rlcompleter</span><br />
<br />
historyPath = <span class="kw3">os</span>.<span class="me1">path</span>.<span class="me1">expanduser</span><span class="br0">&#40;</span><span class="st0">&quot;~/.pyhistory&quot;</span><span class="br0">&#41;</span><br />
<br />
<span class="kw1">def</span> save_history<span class="br0">&#40;</span>historyPath=historyPath<span class="br0">&#41;</span>:<br />
<span class="kw1">import</span> <span class="kw3">readline</span><br />
<span class="kw3">readline</span>.<span class="me1">write_history_file</span><span class="br0">&#40;</span>historyPath<span class="br0">&#41;</span><br />
<br />
<span class="kw1">if</span> <span class="kw3">os</span>.<span class="me1">path</span>.<span class="me1">exists</span><span class="br0">&#40;</span>historyPath<span class="br0">&#41;</span>:<br />
<span class="kw3">readline</span>.<span class="me1">read_history_file</span><span class="br0">&#40;</span>historyPath<span class="br0">&#41;</span><br />
<br />
<span class="kw3">readline</span>.<span class="me1">parse_and_bind</span><span class="br0">&#40;</span><span class="st0">'tab: complete'</span><span class="br0">&#41;</span><br />
<br />
<span class="kw3">atexit</span>.<span class="me1">register</span><span class="br0">&#40;</span>save_history<span class="br0">&#41;</span><br />
<span class="kw1">del</span> <span class="kw3">os</span>, <span class="kw3">atexit</span>, <span class="kw3">readline</span>, <span class="kw3">rlcompleter</span>, save_history, historyPath</div></div>
]]></content:encoded>
			<wfw:commentRss>http://foobar.lu/wp/2008/08/21/python-startup-command-completion-history/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vim script (mapping) to generate python getters and setters</title>
		<link>http://foobar.lu/wp/2007/12/31/vim-script-mapping-to-generate-python-getters-and-setters/</link>
		<comments>http://foobar.lu/wp/2007/12/31/vim-script-mapping-to-generate-python-getters-and-setters/#comments</comments>
		<pubDate>Mon, 31 Dec 2007 09:59:46 +0000</pubDate>
		<dc:creator>exhuma.twn</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://foobar.lu/wp/2007/12/31/vim-script-mapping-to-generate-python-getters-and-setters/</guid>
		<description><![CDATA[Somethin that I need quite often is to create custom accessors and mutators for class-attributes. For example convert this:
class MyClass&#40;object&#41;:
&#160; &#160;
&#160; &#160;def __init__&#40;self&#41;:
&#160; &#160; &#160; self.has_changes = False
&#160; &#160; &#160; self.some_attribute = False
into this:
class MyClass&#40;object&#41;:
&#160; &#160;
&#160; &#160;def __init__&#40;self&#41;:
&#160; &#160; &#160; self.__has_changes = False
&#160; &#160; &#160; self.__some_attribute = False

&#160; &#160;def get_some_attribute&#40;self&#41;:
&#160; &#160; &#160; &#34;Accessor: some_attribute&#34;
&#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Somethin that I need quite often is to create custom accessors and mutators for class-attributes. For example convert this:</p>
<div class="codecolorer-container python twitlight" style="overflow:auto;white-space:nowrap;width:530px"><div class="python codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">class</span> MyClass<span class="br0">&#40;</span><span class="kw2">object</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span class="kw1">def</span> <span class="kw4">__init__</span><span class="br0">&#40;</span><span class="kw2">self</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">has_changes</span> = <span class="kw2">False</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">some_attribute</span> = <span class="kw2">False</span></div></div>
<p>into this:</p>
<div class="codecolorer-container python twitlight" style="overflow:auto;white-space:nowrap;width:530px"><div class="python codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">class</span> MyClass<span class="br0">&#40;</span><span class="kw2">object</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span class="kw1">def</span> <span class="kw4">__init__</span><span class="br0">&#40;</span><span class="kw2">self</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.__has_changes = <span class="kw2">False</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.__some_attribute = <span class="kw2">False</span><br />
<br />
&nbsp; &nbsp;<span class="kw1">def</span> get_some_attribute<span class="br0">&#40;</span><span class="kw2">self</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; <span class="st0">&quot;Accessor: some_attribute&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">self</span>.__some_attribute<br />
<br />
&nbsp; &nbsp;<span class="kw1">def</span> set_some_attribute<span class="br0">&#40;</span><span class="kw2">self</span>, <span class="kw2">input</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; <span class="st0">&quot;Mutator: some_attribute&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.__some_attribute = <span class="kw2">input</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.__has_changes = <span class="kw2">True</span><br />
<br />
&nbsp; &nbsp;some_attribute = <span class="kw2">property</span><span class="br0">&#40;</span>get_some_attribute, set_some_attribute<span class="br0">&#41;</span><br />
<br />
&nbsp; &nbsp;<span class="kw1">def</span> get_has_changes<span class="br0">&#40;</span><span class="kw2">self</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; <span class="st0">&quot;Accessor: has_changes&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">self</span>.__has_changes<br />
<br />
&nbsp; &nbsp;has_changes = <span class="kw2">property</span><span class="br0">&#40;</span>get_has_changes<span class="br0">&#41;</span></div></div>
<p>This particular example allows an easy tracking if a class contains changes. Without the need of calling <tt>myclass.get_some_attribute()</tt> or <tt>myclass.set_some_attribute(foo)</tt>. You can simply do <tt>myclass.some_attribute = foo</tt> and the <tt>has_changes</tt> attribut will change accordingly.</p>
<p>If your class has many attributes, writing custom accessors and mutators can be tedious. So here&#8217;s a small Vim-mapping that get&#8217;s you started. Sure, you may still need to fine-tune some generated code, but the bulk is there.</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;width:530px"><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">&lt;font color=&quot;#808bed&quot;&gt;nmap&lt;/font&gt; &lt;font color=&quot;#c080d0&quot;&gt;&amp;lt;&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;F6&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;&amp;gt;&lt;/font&gt; yyP&lt;font color=&quot;#c080d0&quot;&gt;&amp;lt;&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;home&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;&amp;gt;&lt;/font&gt;widef get_&lt;font color=&quot;#c080d0&quot;&gt;&amp;lt;&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;end&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;&amp;gt;&lt;/font&gt;(self):&lt;font color=&quot;#c080d0&quot;&gt;&amp;lt;&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;esc&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;&amp;gt;&amp;lt;&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;down&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;&amp;gt;&amp;lt;&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;esc&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;&amp;gt;&lt;/font&gt;yyP&amp;gt;&amp;gt;I&amp;quot;Accessor: &lt;font color=&quot;#c080d0&quot;&gt;&amp;lt;&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;end&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;&amp;gt;&lt;/font&gt;&amp;quot;&lt;font color=&quot;#c080d0&quot;&gt;&amp;lt;&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;esc&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;&amp;gt;&amp;lt;&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;down&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;&amp;gt;&lt;/font&gt;yyP&amp;gt;&amp;gt;Ireturn self.__&lt;font color=&quot;#c080d0&quot;&gt;&amp;lt;&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;esc&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;&amp;gt;&lt;/font&gt;o&lt;font color=&quot;#c080d0&quot;&gt;&amp;lt;&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;esc&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;&amp;gt;&amp;lt;&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;down&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;&amp;gt;&lt;/font&gt;yyPIdef set_&lt;font color=&quot;#c080d0&quot;&gt;&amp;lt;&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;end&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;&amp;gt;&lt;/font&gt;(self, input):&lt;font color=&quot;#c080d0&quot;&gt;&amp;lt;&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;esc&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;&amp;gt;&amp;lt;&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;down&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;&amp;gt;&lt;/font&gt;yyP&amp;gt;&amp;gt;I&amp;quot;Mutator: &lt;font color=&quot;#c080d0&quot;&gt;&amp;lt;&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;end&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;&amp;gt;&lt;/font&gt;&amp;quot;&lt;font color=&quot;#c080d0&quot;&gt;&amp;lt;&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;esc&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;&amp;gt;&amp;lt;&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;down&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;&amp;gt;&lt;/font&gt;yyP&amp;gt;&amp;gt;Iself.__&lt;font color=&quot;#c080d0&quot;&gt;&amp;lt;&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;end&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;&amp;gt;&lt;/font&gt; = input&lt;font color=&quot;#c080d0&quot;&gt;&amp;lt;&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;esc&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;&amp;gt;&lt;/font&gt;o&lt;font color=&quot;#c080d0&quot;&gt;&amp;lt;&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;esc&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;&amp;gt;&amp;lt;&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;down&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;&amp;gt;&amp;lt;&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;home&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;&amp;gt;&lt;/font&gt;wveyA = property(get_&lt;font color=&quot;#c080d0&quot;&gt;&amp;lt;&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;esc&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;&amp;gt;&lt;/font&gt;pA, set_&lt;font color=&quot;#c080d0&quot;&gt;&amp;lt;&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;esc&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;&amp;gt;&lt;/font&gt;pA)&lt;font color=&quot;#c080d0&quot;&gt;&amp;lt;&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;esc&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;&amp;gt;&lt;/font&gt;o&lt;font color=&quot;#c080d0&quot;&gt;&amp;lt;&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;esc&lt;/font&gt;&lt;font color=&quot;#c080d0&quot;&gt;&amp;gt;&lt;/font&gt;</div></div>
<p>Put this into your vimrc, or (like I do) into the ~/.vim/ftplugin/python.vim file so it get&#8217;s only loaded for python files. Then you only need to write the attribute name of the class, put your cursor on that line, be sure to be in normal mode (hit a few time &lt;esc&gt;) <img src='http://foobar.lu/wp/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  and hit F6</p>
<p>If you want to change the shortcut, simply change the first parameter to this mapping line.</p>
]]></content:encoded>
			<wfw:commentRss>http://foobar.lu/wp/2007/12/31/vim-script-mapping-to-generate-python-getters-and-setters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Calculate the distance between two GPS-Coordinates</title>
		<link>http://foobar.lu/wp/2007/09/17/calculate-the-distance-between-two-gps-coordinates/</link>
		<comments>http://foobar.lu/wp/2007/09/17/calculate-the-distance-between-two-gps-coordinates/#comments</comments>
		<pubDate>Mon, 17 Sep 2007 08:58:17 +0000</pubDate>
		<dc:creator>exhuma.twn</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://foobar.lu/wp/2007/09/17/calculate-the-distance-between-two-gps-coordinates/</guid>
		<description><![CDATA[This function uses the Haversine formula to calculate the distance which takes into account the spherical nature of the earth.
As the earth is not a perfect sphere, this function approximates this by using the average radius.
from math import sin, cos, radians, sqrt, atan2

def lldistance&#40;a, b&#41;:
&#160; &#160;&#34;&#34;&#34;
&#160; &#160;Calculates the distance between two GPS points (decimal)
&#160; &#160;@param [...]]]></description>
			<content:encoded><![CDATA[<p>This function uses the Haversine formula to calculate the distance which takes into account the spherical nature of the earth.<br />
As the earth is not a perfect sphere, this function approximates this by using the average radius.</p>
<div class="codecolorer-container python twitlight" style="overflow:auto;white-space:nowrap;width:530px"><div class="python codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">from</span> <span class="kw3">math</span> <span class="kw1">import</span> sin, cos, radians, sqrt, atan2<br />
<br />
<span class="kw1">def</span> lldistance<span class="br0">&#40;</span>a, b<span class="br0">&#41;</span>:<br />
&nbsp; &nbsp;<span class="st0">&quot;&quot;&quot;<br />
&nbsp; &nbsp;Calculates the distance between two GPS points (decimal)<br />
&nbsp; &nbsp;@param a: 2-tuple of point A<br />
&nbsp; &nbsp;@param b: 2-tuple of point B<br />
&nbsp; &nbsp;@return: distance in m<br />
&nbsp; &nbsp;&quot;&quot;&quot;</span><br />
&nbsp; &nbsp;r = <span class="nu0">6367442.5</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1"># average earth radius in m</span><br />
&nbsp; &nbsp;dLat = radians<span class="br0">&#40;</span>a<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>-b<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp;dLon = radians<span class="br0">&#40;</span>a<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>-b<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp;x = sin<span class="br0">&#40;</span>dLat/<span class="nu0">2</span><span class="br0">&#41;</span> <span class="sy0">**</span> <span class="nu0">2</span> + \<br />
&nbsp; &nbsp; &nbsp; &nbsp;cos<span class="br0">&#40;</span>radians<span class="br0">&#40;</span>a<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="sy0">*</span> cos<span class="br0">&#40;</span>radians<span class="br0">&#40;</span>b<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="sy0">*</span>\<br />
&nbsp; &nbsp; &nbsp; &nbsp;sin<span class="br0">&#40;</span>dLon/<span class="nu0">2</span><span class="br0">&#41;</span> <span class="sy0">**</span> <span class="nu0">2</span><br />
&nbsp; &nbsp;y = <span class="nu0">2</span> <span class="sy0">*</span> atan2<span class="br0">&#40;</span>sqrt<span class="br0">&#40;</span>x<span class="br0">&#41;</span>, sqrt<span class="br0">&#40;</span><span class="nu0">1</span>-x<span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp;d = r <span class="sy0">*</span> y<br />
<br />
&nbsp; &nbsp;<span class="kw1">return</span> d</div></div>
]]></content:encoded>
			<wfw:commentRss>http://foobar.lu/wp/2007/09/17/calculate-the-distance-between-two-gps-coordinates/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Centering a window on the screen with Qt</title>
		<link>http://foobar.lu/wp/2007/09/10/centering-a-window-on-the-screen-with-qt/</link>
		<comments>http://foobar.lu/wp/2007/09/10/centering-a-window-on-the-screen-with-qt/#comments</comments>
		<pubDate>Mon, 10 Sep 2007 14:26:47 +0000</pubDate>
		<dc:creator>exhuma.twn</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://foobar.lu/wp/2007/09/10/centering-a-window-on-the-screen-with-qt/</guid>
		<description><![CDATA[Yet another thing that&#8217;s not automagic in Qt.
Here&#8217;s a python solution:
if __name__ == &#34;__main__&#34;:

&#160; &#160;app = QtGui.QApplication&#40;sys.argv&#41;

&#160; &#160;dw = app.desktop&#40;&#41;.width&#40;&#41;
&#160; &#160;dh = app.desktop&#40;&#41;.height&#40;&#41;

&#160; &#160;myapp = MainWindow&#40;&#41;
&#160; &#160;myapp.setGeometry&#40;
&#160; &#160; &#160; &#160; &#160;int&#40;&#40;dw - &#40;dw - &#40;dw / 2&#41;&#41; * 1.5&#41; / 2&#41;,
&#160; &#160; &#160; &#160; &#160;int&#40;&#40;dh - &#40;dh - &#40;dh / 2&#41;&#41; * 1.5&#41; / 2&#41;,
&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Yet another thing that&#8217;s not automagic in Qt.<br />
Here&#8217;s a python solution:</p>
<div class="codecolorer-container python twitlight" style="overflow:auto;white-space:nowrap;width:530px"><div class="python codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">if</span> __name__ == <span class="st0">&quot;__main__&quot;</span>:<br />
<br />
&nbsp; &nbsp;app = QtGui.<span class="me1">QApplication</span><span class="br0">&#40;</span><span class="kw3">sys</span>.<span class="me1">argv</span><span class="br0">&#41;</span><br />
<br />
&nbsp; &nbsp;dw = app.<span class="me1">desktop</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">width</span><span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp;dh = app.<span class="me1">desktop</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">height</span><span class="br0">&#40;</span><span class="br0">&#41;</span><br />
<br />
&nbsp; &nbsp;myapp = MainWindow<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp;myapp.<span class="me1">setGeometry</span><span class="br0">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw2">int</span><span class="br0">&#40;</span><span class="br0">&#40;</span>dw - <span class="br0">&#40;</span>dw - <span class="br0">&#40;</span>dw / <span class="nu0">2</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="sy0">*</span> <span class="nu0">1.5</span><span class="br0">&#41;</span> / <span class="nu0">2</span><span class="br0">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw2">int</span><span class="br0">&#40;</span><span class="br0">&#40;</span>dh - <span class="br0">&#40;</span>dh - <span class="br0">&#40;</span>dh / <span class="nu0">2</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="sy0">*</span> <span class="nu0">1.5</span><span class="br0">&#41;</span> / <span class="nu0">2</span><span class="br0">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw2">int</span><span class="br0">&#40;</span><span class="br0">&#40;</span>dw - <span class="br0">&#40;</span>dw / <span class="nu0">2</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="sy0">*</span> <span class="nu0">1.5</span><span class="br0">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw2">int</span><span class="br0">&#40;</span><span class="br0">&#40;</span>dh - <span class="br0">&#40;</span>dh / <span class="nu0">2</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="sy0">*</span> <span class="nu0">1.5</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp;myapp.<span class="me1">show</span><span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp;<span class="kw3">sys</span>.<span class="me1">exit</span><span class="br0">&#40;</span>app.<span class="me1">exec_</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div></div>
<p>This will also resize the window, adapting to the desktop size.<br />
Found and adapted from <a href="http://lists.trolltech.com/qt-interest/2003-08/msg00011.html">the Qt interest archive</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://foobar.lu/wp/2007/09/10/centering-a-window-on-the-screen-with-qt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding Scrollbars to a QFrame in Qt</title>
		<link>http://foobar.lu/wp/2007/09/10/adding-scrollbars-to-a-qframe-in-qt/</link>
		<comments>http://foobar.lu/wp/2007/09/10/adding-scrollbars-to-a-qframe-in-qt/#comments</comments>
		<pubDate>Mon, 10 Sep 2007 09:51:23 +0000</pubDate>
		<dc:creator>exhuma.twn</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://foobar.lu/wp/2007/09/10/adding-scrollbars-to-a-qframe-in-qt/</guid>
		<description><![CDATA[Many things are very easy to accomplish in Qt. Qt&#8217;s designer is a great help with that. But the is no option to simply &#8220;enable&#8221; scrollbars for a frame. Also, the QScrollArea can nowhere be found in the designer. The solution is actually quite simple:

Add the component you want to be scrollable (QFrame, QLabel, &#8230;) [...]]]></description>
			<content:encoded><![CDATA[<p>Many things are very easy to accomplish in Qt. Qt&#8217;s designer is a great help with that. But the is no option to simply &#8220;enable&#8221; scrollbars for a frame. Also, the QScrollArea can nowhere be found in the designer. The solution is actually quite simple:</p>
<ol>
<li>Add the component you want to be scrollable (QFrame, QLabel, &#8230;) in the designer as usual</li>
<li>In the application code:
<ol type="a">
<li>Create a new QScrollArea</li>
<li>Set the parent of the widget you created in the designer to &#8220;None&#8221;</li>
<li>Set the widget of the QScrollArea to the widget from step 1</li>
<li>Insert the QScrollArea to you ui</li>
</ol>
</li>
</ol>
<p>And here&#8217;s some example code (boiled down to the essentials):</p>
<div class="codecolorer-container python twitlight" style="overflow:auto;white-space:nowrap;width:530px"><div class="python codecolorer" style="font-family:Monaco,Lucida Console,monospace">sa = QtGui.<span class="me1">QScrollArea</span><span class="br0">&#40;</span><span class="br0">&#41;</span><br />
<span class="kw2">self</span>.<span class="me1">ui</span>.<span class="me1">myWidget</span>.<span class="me1">setParent</span><span class="br0">&#40;</span><span class="kw2">None</span><span class="br0">&#41;</span><br />
sa.<span class="me1">setWidget</span><span class="br0">&#40;</span><span class="kw2">self</span>.<span class="me1">ui</span>.<span class="me1">myWidget</span><span class="br0">&#41;</span><br />
<span class="kw2">self</span>.<span class="me1">ui</span>.<span class="me1">vboxlayout1</span>.<span class="me1">insertWidget</span><span class="br0">&#40;</span><span class="nu0">0</span>, sa<span class="br0">&#41;</span></div></div>
<p>You would probably write this somewhere in you application-constructor right after you call <tt>setupUi</tt>.</p>
<p>This will insert the scroll area at the top of vboxlayout1 (see <a href="http://www.riverbankcomputing.com/Docs/PyQt4/html/qboxlayout.html#insertWidget">the doc for insertWidget</a>). You can of course also use <a href="http://www.riverbankcomputing.com/Docs/PyQt4/html/qboxlayout.html#addWidget">addWidget</a>.</p>
<p>It&#8217;s a shame that there&#8217;s no direct support for QScrollArea in designer. Maybe we will see it in some future release.</p>
<p>An example for C++ can be found <a href="http://www.qtforum.org/printout/17574/1/How-to-use-QScrollArea-from-QT-Designer.html">in the Qt Forums</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://foobar.lu/wp/2007/09/10/adding-scrollbars-to-a-qframe-in-qt/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Deploying PyQt applications on Windows</title>
		<link>http://foobar.lu/wp/2007/07/12/deploying-pyqt-applications-on-windows/</link>
		<comments>http://foobar.lu/wp/2007/07/12/deploying-pyqt-applications-on-windows/#comments</comments>
		<pubDate>Thu, 12 Jul 2007 11:54:01 +0000</pubDate>
		<dc:creator>exhuma.twn</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://foobar.lu/wp/2007/07/12/deploying-pyqt-applications-on-windows/</guid>
		<description><![CDATA[My preferred way to deploy python applications on Windows is to use py2exe.
py2exe is a Python Distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python installation.
If you run in trouble with sip, read on&#8230;

Sure there are other options to create windows executables. The ones I know of:

Freeze [...]]]></description>
			<content:encoded><![CDATA[<p>My preferred way to deploy python applications on Windows is to use <a href="http://www.py2exe.org/">py2exe</a>.</p>
<blockquote><p>py2exe is a Python Distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python installation.</p></blockquote>
<p>If you run in trouble with <tt>sip</tt>, read on&#8230;<br />
<span id="more-7"></span><br />
Sure there are other options to create windows executables. The ones I know of:</p>
<ul>
<li>Freeze (which comes with python)</li>
<li><a href="http://pyinstaller.hpcf.upr.edu/cgi-bin/trac.cgi">PyInstaller</a></li>
<li><a href="http://starship.python.net/crew/atuining/cx_Freeze/index.html">cx_Freeze</a></li>
<li><a href="http://py2exe.org">py2exe</a></li>
<li><a href="http://effbot.org/zone/exemaker.htm">ExeMaker</a></li>
</ul>
<h3>py2exe</h3>
<p>The reason why I prefer py2exe, and why I would recommend using it, is because it&#8217;s right now the most widely used tool. So you will find lots of hits when googling for it. This is a big bonus. Additionally, it&#8217;s configuration is very flexible, and works well with dependancies (let&#8217;s say you are using SQLAlchemy, or some other third-party python-module).</p>
<p>The others either did not offer enough flexibility or had trouble detecting imported modules. With <em>Freeze</em> I was not even able to get the program to compile following their example scripts.</p>
<h3>py2exe with PyQt</h3>
<p>So you have a Qt program written in python and it works on your machine? Great! To get this to work you actually need to have the Qt libraries and the Python interpreter installed. But you don&#8217;t necessarily want your end-users to install these. To prevent that, you can use py2exe which will give you a directory with all the required libraries, byte-compiled sources and a ready-to-use windows-executable.</p>
<p>In order to create an executable, you write a standard python distutils setup script:</p>
<div class="codecolorer-container python twitlight" style="overflow:auto;white-space:nowrap;width:530px"><div class="python codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">from</span> <span class="kw3">distutils</span>.<span class="me1">core</span> <span class="kw1">import</span> setup<br />
<span class="kw1">import</span> py2exe<br />
setup<span class="br0">&#40;</span><br />
&nbsp; &nbsp;windows = <span class="br0">&#91;</span><span class="br0">&#123;</span><span class="st0">&quot;script&quot;</span>: <span class="st0">&quot;MyApplication.py&quot;</span><span class="br0">&#125;</span><span class="br0">&#93;</span><br />
&nbsp; &nbsp;<span class="br0">&#41;</span></div></div>
<p>Then you can create the executable running the setup script with &#8220;py2exe&#8221; as build target:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;width:530px"><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace">$ python setup.py py2exe</div></div>
<p>With Qt you will run into trouble however. You will most certainly get an error along the lines:</p>
<div class="codecolorer-container python twitlight" style="overflow:auto;white-space:nowrap;width:530px"><div class="python codecolorer" style="font-family:Monaco,Lucida Console,monospace">File <span class="st0">&quot;mainwindow.pyc&quot;</span>, line <span class="nu0">11</span>, <span class="kw1">in</span> <span class="sy0">?</span><br />
&nbsp; File <span class="st0">&quot;qt.pyc&quot;</span>, line <span class="nu0">9</span>, <span class="kw1">in</span> <span class="sy0">?</span><br />
&nbsp; File <span class="st0">&quot;qt.pyc&quot;</span>, line <span class="nu0">7</span>, <span class="kw1">in</span> __load<br />
<span class="kw2">ImportError</span>: No module named sip</div></div>
<p>The reason here is that the <tt>sip</tt> module is required by PyQt, and it&#8217;s not found in a place where py2exe could see that. So you need to tell py2exe to include <tt>sip</tt> even though it does not seem to be imported anywhere:</p>
<div class="codecolorer-container python twitlight" style="overflow:auto;white-space:nowrap;width:530px"><div class="python codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">from</span> <span class="kw3">distutils</span>.<span class="me1">core</span> <span class="kw1">import</span> setup<br />
<span class="kw1">import</span> py2exe<br />
setup<span class="br0">&#40;</span><br />
&nbsp; &nbsp;windows = <span class="br0">&#91;</span><span class="br0">&#123;</span><span class="st0">&quot;script&quot;</span>: <span class="st0">&quot;MyApplication.py&quot;</span><span class="br0">&#125;</span><span class="br0">&#93;</span>,<br />
&nbsp; &nbsp;options = <span class="br0">&#123;</span><span class="st0">&quot;py2exe&quot;</span>:<span class="br0">&#123;</span><span class="st0">&quot;includes&quot;</span>:<span class="br0">&#91;</span><span class="st0">&quot;sip&quot;</span><span class="br0">&#93;</span><span class="br0">&#125;</span><span class="br0">&#125;</span><br />
&nbsp; &nbsp;<span class="br0">&#41;</span></div></div>
<p>This will take care of this problem, an your application should run just fine on windows.</p>
<h3>Note</h3>
<p>py2exe will give you a list of additional dll&#8217;s that <em>may</em> be needed. So far I could live without these dll&#8217;s. If you want to be on the safe side, you could include those dll&#8217;s into your project. But with the python-interpreter and the Qt libraries, your project will already be bloated enough (usually around 20MB). So there&#8217;s no need to waste even more space. But, as always, your mileage may vary!</p>
]]></content:encoded>
			<wfw:commentRss>http://foobar.lu/wp/2007/07/12/deploying-pyqt-applications-on-windows/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Writing Qt apps in python</title>
		<link>http://foobar.lu/wp/2007/07/02/writing-qt-apps-in-python/</link>
		<comments>http://foobar.lu/wp/2007/07/02/writing-qt-apps-in-python/#comments</comments>
		<pubDate>Mon, 02 Jul 2007 20:20:23 +0000</pubDate>
		<dc:creator>exhuma.twn</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://foobar.lu/wp/2007/07/02/writing-qt-apps-in-python/</guid>
		<description><![CDATA[Writing Qt apps in Python with Qt3 worked. Somewhat. I never found the energy to get it all set up. Finally with Qt4 we have something that &#8220;just works&#8221;. At least on Ubuntu and Windows (haven&#8217;t tested anywhere else).
Yes, since version 4, trolltech finally decided to release Qt as well under the GPL. To most [...]]]></description>
			<content:encoded><![CDATA[<p>Writing Qt apps in Python with Qt3 worked. Somewhat. I never found the energy to get it all set up. Finally with Qt4 we have something that &#8220;just works&#8221;. At least on Ubuntu and Windows (haven&#8217;t tested anywhere else).</p>
<p>Yes, since version 4, trolltech finally decided to release Qt as well under the GPL. To most of you it&#8217;s all old news. But hey&#8230;. just felt like writing it down again <img src='http://foobar.lu/wp/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>The problems with SIP are finally gone. So you just install python, Qt4 and pyqt4 and off you go.</p>
<p><span id="more-10"></span></p>
<p>Writing apps is actually a breeze. You fire up the Qt-Designer, drag and drop some widgets on your form, and save the Form as a .ui file.</p>
<p>Next you generate the python-code for the form with pyuic4. Let&#8217;s say you created &#8220;MainForm.ui&#8221;. The you just do:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;width:530px"><div class="text codecolorer" style="font-family:Monaco,Lucida Console,monospace"># pyuic4 MainForm.ui &amp;gt; ui_mainform.py</div></div>
<p>Actually the name &#8220;ui_mainform.py&#8221; is fully up to you.</p>
<p>But this script does not have an entry-point, so just typing &#8220;python ui_mainform.py&#8221; will silently return. For those of you that just thought: &#8220;Hey, I read the man-page, and used the &#8220;-x&#8221; parameter with pyuic4&#8243;.  Sure. You can do that. But you shouldn&#8217;t. Just bear with me a second.</p>
<p>The cleanest way to run your application is to write a startup script. A copy/paste example:</p>
<div class="codecolorer-container python twitlight" style="overflow:auto;white-space:nowrap;width:530px"><div class="python codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">import</span> <span class="kw3">sys</span><br />
<span class="kw1">from</span> PyQt4 <span class="kw1">import</span> QtCore, QtGui<br />
<span class="kw1">from</span> ui_mainform <span class="kw1">import</span> Ui_MainWindow<br />
<br />
<span class="kw1">class</span> MyForm<span class="br0">&#40;</span>QtGui.<span class="me1">QMainWindow</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp;<span class="kw1">def</span> <span class="kw4">__init__</span><span class="br0">&#40;</span><span class="kw2">self</span>, parent=<span class="kw2">None</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; QtGui.<span class="me1">QWidget</span>.<span class="kw4">__init__</span><span class="br0">&#40;</span><span class="kw2">self</span>, parent<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">ui</span> = Ui_MainWindow<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">ui</span>.<span class="me1">setupUi</span><span class="br0">&#40;</span><span class="kw2">self</span><span class="br0">&#41;</span><br />
<br />
<span class="kw1">if</span> __name__ == <span class="st0">&quot;__main__&quot;</span>:<br />
&nbsp; &nbsp;app = QtGui.<span class="me1">QApplication</span><span class="br0">&#40;</span><span class="kw3">sys</span>.<span class="me1">argv</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp;myapp = MyForm<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp;myapp.<span class="me1">show</span><span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp;<span class="kw3">sys</span>.<span class="me1">exit</span><span class="br0">&#40;</span>app.<span class="me1">exec_</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div></div>
<h3>So why not just &#8220;pyuic4 -x&#8221; ?</h3>
<p>Simple. Whenever you run this, you will overwrite your old code. And you will inevitably want to complement your user-interface with some program logic. Otherwise your application won&#8217;t do much. So if you put your business-logic into the generated code, you will always end up cutting and pasting things about. And that clearly violates the &#8220;Don&#8217;t repeat yourself&#8221; dogma. So: You be nice, take the startup script and stick your logic in there. Like that you can recreate/regenerate the user-interface from the .ui file without ever (well&#8230; nearly) touching yor business-logic-code.</p>
<p>For some programming examples, head right over to <a href="http://www.rkblog.rk.edu.pl/w/p/python/" title="Riklaunim's TechBlog">Riklaunim&#8217;s TechBlog</a>. There&#8217;s some most excellent examples for pyqt4. You might see, I &#8220;borrowed&#8221; the startup script from there too!</p>
<h3>A note for Windows users</h3>
<p>To get python and Qt working, you need to take care of the version numbers mentioned in the file names of pyqt. Please use the proper Qt version with your pyqt download</p>
<p>As you might have noticed, you also need MingW (a free GNU build environment for windows. Includes C-compiler, libraries, yadda yadda&#8230;). Somewhere along the installation, you might get an error nagging you about the win32api. You can happily ignore this and just continue. I have not yet encountered any problems.</p>
]]></content:encoded>
			<wfw:commentRss>http://foobar.lu/wp/2007/07/02/writing-qt-apps-in-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Runnning a twisted application as windows service</title>
		<link>http://foobar.lu/wp/2007/06/27/runnning-a-twisted-application-as-windows-service/</link>
		<comments>http://foobar.lu/wp/2007/06/27/runnning-a-twisted-application-as-windows-service/#comments</comments>
		<pubDate>Wed, 27 Jun 2007 12:47:20 +0000</pubDate>
		<dc:creator>exhuma.twn</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://foobar.lu/wp/2007/06/27/runnning-a-twisted-application-as-windows-service/</guid>
		<description><![CDATA[Currently I am a bit busy, so I will just dump the post I found on usenet. Eventually I will clean it up&#8230;
On Wed, 22 Oct 2003 12:24:42 -0600
"Justin Johnson" &#60;justinjohnson@fastmail.fm&#62; wrote:

&#62; The general consensus on the mailing list archives seems to be that
&#62; I'd need to setup my code to not require twistd but [...]]]></description>
			<content:encoded><![CDATA[<p>Currently I am a bit busy, so I will just dump the post I found on usenet. Eventually I will clean it up&#8230;</p>
<pre>On Wed, 22 Oct 2003 12:24:42 -0600
"Justin Johnson" &lt;justinjohnson@fastmail.fm&gt; wrote:

&gt; The general consensus on the mailing list archives seems to be that
&gt; I'd need to setup my code to not require twistd but just run
&gt; standalone.

Uh. *Maybe* that's the consensus, but it's not actually correct. You can
have a tap or tac run as a NT service.

Lets say you have  a script "server.py" that is runnable with "twistd
-y", you can do (and similar code will work for TAPs):</pre>
<div class="codecolorer-container python twitlight" style="overflow:auto;white-space:nowrap;width:530px"><div class="python codecolorer" style="font-family:Monaco,Lucida Console,monospace"><span class="kw1">import</span> <span class="kw3">sys</span>, <span class="kw3">os</span><br />
<span class="kw1">import</span> win32serviceutil, win32service<br />
<br />
<span class="kw1">class</span> MyService<span class="br0">&#40;</span>win32serviceutil.<span class="me1">ServiceFramework</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; <span class="st0">&quot;&quot;&quot;NT Service.&quot;&quot;&quot;</span><br />
<br />
&nbsp; &nbsp; _svc_name_ = <span class="st0">&quot;MyService&quot;</span><br />
&nbsp; &nbsp; _svc_display_name_ = <span class="st0">&quot;MyService server&quot;</span><br />
<br />
&nbsp; &nbsp; <span class="kw1">def</span> SvcDoRun<span class="br0">&#40;</span><span class="kw2">self</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">import</span> server<br />
&nbsp; &nbsp; &nbsp; &nbsp; f = <span class="kw2">open</span><span class="br0">&#40;</span><span class="kw3">os</span>.<span class="me1">path</span>.<span class="me1">join</span><span class="br0">&#40;</span>server.<span class="me1">rootPath</span>, <span class="st0">&quot;cyberhigh.log&quot;</span><span class="br0">&#41;</span>, <span class="st0">'a'</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">from</span> twisted.<span class="me1">python</span>.<span class="me1">log</span> <span class="kw1">import</span> startLogging<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">from</span> twisted.<span class="me1">application</span>.<span class="me1">app</span> <span class="kw1">import</span> startApplication<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">from</span> twisted.<span class="me1">internet</span> <span class="kw1">import</span> reactor<br />
&nbsp; &nbsp; &nbsp; &nbsp; startLogging<span class="br0">&#40;</span>f<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; startApplication<span class="br0">&#40;</span>server.<span class="me1">application</span>, <span class="nu0">0</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; reactor.<span class="me1">run</span><span class="br0">&#40;</span><span class="br0">&#41;</span><br />
<br />
&nbsp; &nbsp; <span class="kw1">def</span> SvcStop<span class="br0">&#40;</span><span class="kw2">self</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">ReportServiceStatus</span><span class="br0">&#40;</span>win32service.<span class="me1">SERVICE_STOP_PENDING</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">from</span> twisted.<span class="me1">internet</span> <span class="kw1">import</span> reactor<br />
&nbsp; &nbsp; &nbsp; &nbsp; reactor.<span class="me1">stop</span><span class="br0">&#40;</span><span class="br0">&#41;</span><br />
<br />
<span class="kw1">if</span> __name__ == <span class="st0">'__main__'</span>:<span class="sy0">&lt;</span>/pre<span class="sy0">&gt;</span><br />
&nbsp; &nbsp; win32serviceutil.<span class="me1">HandleCommandLine</span><span class="br0">&#40;</span>MyService<span class="br0">&#41;</span><span class="sy0">&lt;</span>/pre<span class="sy0">&gt;</span></div></div>
<pre>
--
Itamar Shtull-Trauring    http://itamarst.org/
Available for Python &amp; Twisted consulting</pre>
<p><span class="postbody"></span><span class="postbody"><br />
</span></p>
]]></content:encoded>
			<wfw:commentRss>http://foobar.lu/wp/2007/06/27/runnning-a-twisted-application-as-windows-service/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
