<?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>Eric Leclerc &#187; pythonEric Leclerc</title>
	<atom:link href="http://eleclerc.ca/category/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://eleclerc.ca</link>
	<description>Web Developer in Gatineau</description>
	<lastBuildDate>Mon, 14 May 2012 20:15:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>How to waste time on google wave</title>
		<link>http://eleclerc.ca/2009/10/21/how-to-waste-time-on-google-wave/</link>
		<comments>http://eleclerc.ca/2009/10/21/how-to-waste-time-on-google-wave/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 02:31:32 +0000</pubDate>
		<dc:creator>Eric Leclerc</dc:creator>
				<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.danceric.net/?p=622</guid>
		<description><![CDATA[You really want to do that? Easy enough, just add danceric-hangman[at]appspot.com to any wave, and start playing hangman game in text mode. The code is on github at: http://github.com/danceric/wave-hangman P.S.: As always, keep in mind that this was done to learn a little more bit about Google Wave and Python, so don&#8217;t expect the best&#8230; <a href="http://eleclerc.ca/2009/10/21/how-to-waste-time-on-google-wave/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>You really want to do that? Easy enough, just add danceric-hangman[at]appspot.com to any wave, and start playing hangman game in text mode.</p>

<p>The code is on github at: <a href="http://github.com/danceric/wave-hangman">http://github.com/danceric/wave-hangman</a></p>

<p>P.S.: As always, keep in mind that this was done to learn a little more bit about Google Wave and Python, so don&#8217;t expect the best game ever.</p>

<p>P.P.S.: I know the name <code>danceric-hangman</code> may sound self-centered, but it&#8217;s hard to find a free appID on appspot nowadays.</p>
]]></content:encoded>
			<wfw:commentRss>http://eleclerc.ca/2009/10/21/how-to-waste-time-on-google-wave/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Update On My Python Learning</title>
		<link>http://eleclerc.ca/2009/10/06/update-on-my-python-learning/</link>
		<comments>http://eleclerc.ca/2009/10/06/update-on-my-python-learning/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 16:39:56 +0000</pubDate>
		<dc:creator>Eric Leclerc</dc:creator>
				<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.danceric.net/?p=599</guid>
		<description><![CDATA[Some other projects haves slowed down my Python learning progress, but things are now geting back to normal. I&#8217;ve read a lot of documentation on Python (the official tutorial, PQR, diveintopython2-3, etc), and now it&#8217;s time to get my hands dirty. I&#8217;ve build a simple blog (you know, &#8216;blog&#8217; is the new &#8216;hello, world!&#8217;) using&#8230; <a href="http://eleclerc.ca/2009/10/06/update-on-my-python-learning/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Some other projects haves slowed down my Python learning progress, but things are now geting back to normal. I&#8217;ve read a lot of documentation on Python (the official tutorial, PQR, diveintopython2-3, etc), and now it&#8217;s time to get my hands dirty.</p>

<p>I&#8217;ve build a simple blog (you know, &#8216;blog&#8217; is the new &#8216;hello, world!&#8217;) using the webapp framework on Google Appengine (<a href="http://github.com/danceric/pythonorbust">code</a>/<a href="http://pythonorbust.appspot.com/">demo</a>). Next planned steps are, in no particular order:</p>

<ul>
<li>finish reading (the dead tree version of) <a href="http://djangobook.com/en/2.0/">The Django Book</a> and port a web app of mine to Django</li>
<li>take the <a href="http://www.pythonchallenge.com/">Python Challenge</a></li>
<li>read <a href="http://www.greenteapress.com/thinkpython/thinkpython.html">Think Python</a>
<br /><br /></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://eleclerc.ca/2009/10/06/update-on-my-python-learning/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Django, virtualenv and mod_wsgi</title>
		<link>http://eleclerc.ca/2009/03/26/django-virtualenv-and-mod_wsgi/</link>
		<comments>http://eleclerc.ca/2009/03/26/django-virtualenv-and-mod_wsgi/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 23:33:12 +0000</pubDate>
		<dc:creator>Eric Leclerc</dc:creator>
				<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://danceric.net/?p=236</guid>
		<description><![CDATA[I&#8217;ve been working with Python and Django lately, here&#8217;s my configuration for future reference The setup I&#8217;ve got a test website built with Django and it&#8217;s running on a VPS (at Linode). the setup is as follow Ubuntu 8.04 LTS with the Apache preform MPM package python virtualenv Django mod_wsgi 2.4 Some explanation on the&#8230; <a href="http://eleclerc.ca/2009/03/26/django-virtualenv-and-mod_wsgi/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working with Python and Django lately, here&#8217;s my configuration for future reference</p>

<h3>The setup</h3>

<p>I&#8217;ve got a test website built with Django and it&#8217;s running on a VPS (at Linode). the setup is as follow</p>

<ul>
<li>Ubuntu 8.04 LTS with the Apache preform MPM package</li>
<li>python virtualenv</li>
<li>Django</li>
<li>mod_wsgi 2.4</li>
</ul>

<h3>Some explanation on the setup</h3>

<p>As I plan to have many website on this server, I want to be able to use different version of some libraries (I don&#8217;t always have the time to update every website for each new Django release). That&#8217;s why I use Virtualenv</p>

<p>My setup use apache prefork because of php.net recommend it (and Passenger needs it, keep an open door for Sinatra) and mod_wsgi in deamon mode (wsgi 2.4 (branches/wsgi-2.x) from svn because of the backport addsitedir())</p>

<h3>Setting up virtualenv</h3>

<pre><code>python virtualenv.py --no-site-packages pythonenv
cd pythonenv
source bin/activate
</code></pre>

<p>from there, path have been changed to user this virtualenv, I can install django the usual way</p>

<pre><code>easy_install django 
</code></pre>

<p>(type <code>deactivate</code> to return to your standard path, read more about virtualenv)</p>

<h3>Setting up django</h3>

<p>Once your virtualenv is activated, you can build your Django apps the usual way</p>

<h3>Installing mod_wsgi</h3>

<p>mod_wsgi >= 2.4 is needed, because of the backporting from 3.0 of the reodering of the path afet a call to addsitedir()</p>

<p>As of today, 2.3 is the stable release, so we&#8217;ll fetch 2.4 from svn:</p>

<pre><code>svn co http://modwsgi.googlecode.com/svn/branches/mod_wsgi-2.X mod_wsgi-2.x
cd !$
.configure
make
sudo make install
</code></pre>

<p>On my Ubuntu 8.04, the apache configuration was done automatically (you may have to run a2enmod mod-wsgi).</p>

<h3>Setting up the Apache config for mod_wsgi</h3>

<p>I&#8217;ll assume here that you know how to use virtual host. Next step is to create the config for mod_wsgi</p>

<p>in <code>/etc/apache2/sites-available/django-test</code></p>

<pre><code>&lt;VirtualHost *&gt;
    ServerName example.com

    Alias /static/ /path/to/my/django/project/static/

    # I'm new to mod_wsgi
    # throw a lot of output so I can debut and learn what's happening
    LogLevel info

    WSGIDaemonProcess example.com display-name=%{GROUP}
    WSGIProcessGroup example.com
    WSGIScriptAlias / /path/to/your/django/project/application.wsgi

    &lt;Directory /path/to/my/django/project&gt;
        Order deny,allow
        Allow from all
    &lt;/Directory&gt;
&lt;/VirtualHost&gt;
</code></pre>

<p>Some explanation on the settings</p>

<ul>
<li>WSGIDaemonProcess: mod_wsgi default to embeded mode, which give you more performance, but have the downside that you need to restart apache when you want to reload your application to apply changes. Using this directive will switch it to Daemon mode (with it, you can reload your application by touching your application.wsgi

<ul>
<li><em>display-name is used to show a different name when you run ps, will show the groupname as {wsgi:example.com}</em></li>
<li>there&#8217;s a lot of other parameters that you can give, like threads=15, or process=2. go read the doc if needed</li>
</ul></li>
<li>WSGIScriptAlias: the first / tell mod_wsgi to take care of every requested url that start with a slash, and use the applications.wsgi to handle it</li>
</ul>

<h3>Testing the apache/mod_wsgi setup</h3>

<p>Just to test that your mod_wsgi is working with this config, create an application.wsgi file in your django project folder (were not involving django for now)</p>

<pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> application<span style="color: black;">&#40;</span>environ, start_response<span style="color: black;">&#41;</span>:
    start_response<span style="color: black;">&#40;</span><span style="color: #483d8b;">'200 OK'</span>, <span style="color: black;">&#91;</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'content-Type'</span>, <span style="color: #483d8b;">'text/html'</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#91;</span><span style="color: #483d8b;">'Hello World'</span><span style="color: black;">&#93;</span></pre>

<p>You may now restart apache (sudo apache2ctl restart (or graceful)) an nagigate the virtual host with your browser, you should see Hello World. If not, you can check the apache log file</p>

<pre><code>/var/log/apache2/error.log
</code></pre>

<h3>Setting up Django to act as a wsgi application</h3>

<p>If everything is working, you may now create a wsgi application for your django project. Replace the file named application.wsgi in you Django project folder with the following content:</p>

<pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">site</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># One directory above the project, so project name will be needed for imports</span>
root_dir = <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">abspath</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">dirname</span><span style="color: black;">&#40;</span>__file__<span style="color: black;">&#41;</span>, <span style="color: #483d8b;">'..'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># with mod_wsgi &gt;= 2.4, this line will add this path in front of the python path</span>
<span style="color: #dc143c;">site</span>.<span style="color: black;">addsitedir</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>root_dir, <span style="color: #483d8b;">'lib/python2.5/site-packages'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># add this django project</span>
<span style="color: #dc143c;">sys</span>.<span style="color: black;">path</span>.<span style="color: black;">append</span><span style="color: black;">&#40;</span>root_dir<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #dc143c;">os</span>.<span style="color: black;">environ</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'DJANGO_SETTINGS_MODULE'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">'subyt.settings'</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> django.<span style="color: black;">core</span>.<span style="color: black;">handlers</span>.<span style="color: black;">wsgi</span>
&nbsp;
application = django.<span style="color: black;">core</span>.<span style="color: black;">handlers</span>.<span style="color: black;">wsgi</span>.<span style="color: black;">WSGIHandler</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre>

<p>The important line here is the &#8216;site.addsitedir&#8217; one. That set your virtualenv path at the top of the python path, so your library are used before those of the main python install</p>

<h3>Setting up a web.py project with mod_wsgi</h3>

<p>Sometime I have some simple page/apps where that would be overkill to use Django, so I also use web.py. It&#8217;s almost the same setup, but instead of calling this in your webpy-app-file.py</p>

<pre class="python" style="font-family:monospace;">application = web.<span style="color: black;">application</span><span style="color: black;">&#40;</span>urls, <span style="color: #008000;">globals</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre>

<p>just call this</p>

<pre class="python" style="font-family:monospace;">application = web.<span style="color: black;">application</span><span style="color: black;">&#40;</span>urls, <span style="color: #008000;">globals</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>.<span style="color: black;">wsgifunc</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre>

<p>Now point you WSGIScriptAlias to this file and voila! Please note that if your using web.py with virtualenv, you&#8217;ll have to add the site.addsitedir() as in the Django example</p>

<p><strong>update 2009-04-01</strong>: if you&#8217;re not using virtualenv (which I don&#8217;t recommend), you can follow some easier instructions, as <a href="http://docs.djangoproject.com/en/1.0/howto/deployment/">Django documentation now recommend mod_wsgi for deployment</a></p>
]]></content:encoded>
			<wfw:commentRss>http://eleclerc.ca/2009/03/26/django-virtualenv-and-mod_wsgi/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Progress with Python</title>
		<link>http://eleclerc.ca/2009/03/19/progress-with-python/</link>
		<comments>http://eleclerc.ca/2009/03/19/progress-with-python/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 13:12:11 +0000</pubDate>
		<dc:creator>Eric Leclerc</dc:creator>
				<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://danceric.net/?p=231</guid>
		<description><![CDATA[Three weeks ago, I have decided to use my free time to re-learn python. My first step was reading the book Python: Visual QuickStart Guide which is really pleasant to read, and a short one too (found the dead-tree version for only $15). I also keep these reference close to me at all time Python&#8230; <a href="http://eleclerc.ca/2009/03/19/progress-with-python/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Three weeks ago, I have decided to use my free time to <a href="http://danceric.net/2009/02/24/python/">re-learn python</a>. My first step was reading the book <a href="http://www.amazon.ca/Python-Visual-QuickStart-Toby-Donaldson/dp/0321585445/ref=sr_1_26?ie=UTF8&amp;s=books&amp;qid=1237380661&amp;sr=1-26">Python: Visual QuickStart Guide</a> which is really pleasant to read, and a short one too (found the dead-tree version for only $15).</p>

<p>I also keep these reference close to me at all time</p>

<ul>
<li><a href="http://rgruet.free.fr/">Python Quick Reference</a></li>
<li><a href="http://diveintopython.org">Dive into Python</a> which is a little bit outdated but still really useful</li>
<li>I keep an eye on the sequel too, still in writing <a href="http://diveintopython3.org">Dive into Python 3</a></li>
</ul>

<p>I&#8217;ve created a couple of easy scripts first, and then I have started to play with web frameworks.
First one was web2py. It was fun, but the website looks like a java ad, which scared me. I may come back to it later. Then I went to try web.py, prototyped a website in a snap, and got it running easily.</p>

<p>Next thing I&#8217;ve done, is reading the &#8220;Definitive Guide to Pylons&#8221;, because the philosophy behind pylons interest me. Putting together a lot of great component that can be reused outside of Pylons is a neat idea, and it play well with the community. The book taught me a lot of thing, but it makes Pylons look overcomplicated&#8230; I feel that I&#8217;m not going to save any time by using this framework. Maybe I wasn&#8217;t ready for that. But still, I have learned about a lot of new stuff from this book: mako, sphinx, sqlalchemy, virtualenv and wsgi.</p>

<p>I&#8217;ve had some apprehension with Django, mainly because they seem to live in their own universe (don&#8217;t quote me on that, I may regret it later). But I have kept an open mind and tried it. Honestly, when coming from Symfony, Django is beautiful and really easy to grasp, I&#8217;ve got a Django website running on my VPS at Linode in no time.</p>

<p>Now before I go deeper with a selected framework, I also want to take a look at some other ones (i.e.: try their tutorial) and I want to learn/work more with <a href="http://www.python.org/dev/peps/pep-0333/">PEP 333</a>.</p>

<p>Ultimately I will choose a full stack framework to invest more time in it. Here&#8217;s my choice so far:</p>

<ul>
<li>Django</li>
<li>Pylons</li>
<li>TurboGears</li>
<li>Web2py</li>
</ul>

<p>I also want to find a small one to quickly test stuff, or create small web app and API (like Sinatra or Ramaze). Available choice seems to be:</p>

<ul>
<li>CherryPy</li>
<li>Juno</li>
<li>web.py</li>
<li>Werkzeug</li>
</ul>

<p>I know there is a gazillion other frameworks in python, but I want to use one with a good user base. Working alone is rarely a good idea.</p>

<p>to be continued…</p>
]]></content:encoded>
			<wfw:commentRss>http://eleclerc.ca/2009/03/19/progress-with-python/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Python</title>
		<link>http://eleclerc.ca/2009/02/24/python/</link>
		<comments>http://eleclerc.ca/2009/02/24/python/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 15:48:59 +0000</pubDate>
		<dc:creator>Eric Leclerc</dc:creator>
				<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://danceric.net/?p=191</guid>
		<description><![CDATA[From 1999-2002, I wasn&#8217;t doing a lot of web development, I was a Powerbuilder programmer. and on some project, I was working with QPL (http://qpl.gao.gov/). It don&#8217;t remember a lot from these glorious day, but the thing I do remember is how buggy Powerbuilder 6.0 was at the time (and how painful it was to&#8230; <a href="http://eleclerc.ca/2009/02/24/python/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>From 1999-2002, I wasn&#8217;t doing a lot of web development, I was a Powerbuilder programmer. and on some project, I was working with QPL (http://qpl.gao.gov/). It don&#8217;t remember a lot from these glorious day, but the thing I do remember is how buggy Powerbuilder 6.0 was at the time (and how painful it was to modify a datawindow on any version up to 8.0), and how boring it was to code in QPL (things my have changes, I haven&#8217;t checked this project since 2003). To ease the coding I was parsing/modifying/creating code with a lot of Python scripts (and some Perl one). I&#8217;ve stopped programming in Python in 2003, because PHP was more trendy&#8230;</p>

<p>Now, after 6 years with PHP, I want to expand my horizon. I&#8217;ve tried Ruby, totally fell in love with Sinatra, the only downside of ruby is that it&#8217;s &#8220;trendy&#8221; right now. And I want to stay away from that for some time. Now that web development with Python is something realistic (was painful in the days of CGI imho), I want to get my Python skills back.</p>

<p>My first goal is to create a Youtube Niche engine with web.py. A small simple framework that will not get in the way as I&#8217;m re-learning Python. Then I will try both Django and Pylons to re-create my YouTube Niche engine, to see which framework feel more comfortable to me.</p>

<p>Having worked with the Symfony framework (in PHP land) a lot, I will probably start with Django, as it seems to have inspired a lot the development of Symfony. Then I will try Pylons, because it seem more decoupled, and that would be useful to be able to reuse stuff in non-web project.</p>

<p>to be continued&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://eleclerc.ca/2009/02/24/python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

