<?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>Endlessly Curious &#187; Python</title>
	<atom:link href="http://www.endlesslycurious.com/category/programming/python-programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.endlesslycurious.com</link>
	<description>by Daniel Brown</description>
	<lastBuildDate>Thu, 03 Jun 2010 16:53:04 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Installing MatPlotLib on Snow Leopard with MacPorts</title>
		<link>http://www.endlesslycurious.com/2009/12/08/installing-matplotlib-on-snow-leopard-with-macports/</link>
		<comments>http://www.endlesslycurious.com/2009/12/08/installing-matplotlib-on-snow-leopard-with-macports/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 09:00:13 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[HowTo]]></category>

		<guid isPermaLink="false">http://www.endlesslycurious.com/?p=1357</guid>
		<description><![CDATA[I have been trying to install the excellent MatPlotLib graphing module for the Python programming language on my iMac for a while now. Unlike most python module installations I&#8217;ve done the excellent python SetupTools (a.k.a easy_install) has not been up to the task.  So I ended up using MacPorts (version 1.8.1) to get MatPlotLib (version 0.99.1.1) installed on Snow [...]]]></description>
			<content:encoded><![CDATA[<p>I have been trying to install the excellent <a href="http://matplotlib.sourceforge.net/index.html">MatPlotLib</a> graphing module for the <a href="http://www.python.org/">Python</a> programming language on my iMac for a while now. Unlike most python module installations I&#8217;ve done the excellent python <a href="http://pypi.python.org/pypi/setuptools">SetupTools</a> (a.k.a easy_install) has not been up to the task.  So I ended up using <a href="http://www.macports.org/">MacPorts</a> (version 1.8.1) to get MatPlotLib (version 0.99.1.1) installed on <a title="Apple.com" href="http://www.apple.com/macosx/">Snow Leopard</a> (OS X 10.6.2) with X-Code (3.2.1 &#8211; 1613).</p>
<p>So here is a brief description of how to do it:</p>
<ol>
<li>Install the <a href="http://developer.apple.com/tools/xcode/">X-Code</a> developer tools (for GCC, make and other build tools) from your Snow Leopard installation DvD.</li>
<li>Install the <a href="http://en.wikipedia.org/wiki/X_Window_System">X11</a> Window System from your Snow Leopard installation DvD.</li>
<li>Run &#8216;<a href="http://www.apple.com/softwareupdate/">Software Update</a>&#8216; from the apple menu on your Mac to get the latest X-Code updates.</li>
<li>Download the latest MacPorts installer (.dmg file extension) for Snow Leopard from here: <a title="Mac Ports" href="http://distfiles.macports.org/MacPorts/">http://distfiles.macports.org/MacPorts/</a>.</li>
<li>Mount the installer image file (.dmg) and run the contained MacPorts installer (.pkg).</li>
<li>Once installation is complete open a terminal window from Applications-&gt;Utilities-&gt;Terminal.</li>
<li>Type &#8216;<span style="color: #008000;">port</span>&#8216; at the terminal then press enter to run MacPorts.  You should see output like the following if it installed correctly:<br />
<span style="color: #808000;">MacPorts 1.8.1<br />
Entering interactive mode&#8230; (&#8220;help&#8221; for help, &#8220;quit&#8221; to quit)</span><br />
Then type &#8216;<span style="color: #008000;">quit</span>&#8216; then press enter to exit port&#8217;s interactive mode.</li>
<li>Type &#8216;<span style="color: #008000;">sudo port selfupdate</span>&#8216; and press enter to update MacPorts to the latest version.  You will be asked to enter the administrators password before continuing.  Depending on how new the version you downloaded is, MacPorts may do some upgrading.</li>
<li>Once the update is finished type &#8216;<span style="color: #008000;">sudo port install py26-matplotlib</span>&#8216; and press enter.  This will attempt to install the latest version of matplotlib for Python version 2.6.*.   You may be asked to enter the administrators password before continuing.  MacPorts will now download, configure, build and stage the dependencies needed to build the latest matplotlib for Python 2.6.  This took at least thirty minutes on my iMac and involved lots and lots of scrolling text output from the build process.</li>
<li>Next we need to switch our environment to use version 2.6.* of Python that MacPorts just built and installed with matplotlib.  To do this run the following two commands, note you may be asked to enter the administrators password before continuing:
<ol>
<li>&#8216;<span style="color: #008000;">sudo port install python_select</span>&#8216; and hit enter.</li>
<li>&#8216;<span style="color: #008000;">sudo python_select python26</span>&#8216; and hit enter.</li>
</ol>
</li>
<li>To test this all worked type the following: &#8216;python -V&#8217; and hit enter.  You should see output like &#8216;<span style="color: #808000;">Python 2.6.4</span>&#8216; which should match the version of python MacPorts built and installed.</li>
<li>Finally to test if matplotlib was installed correctly do the following:
<ol>
<li>Type &#8216;<span style="color: #008000;">python</span>&#8216; and hit enter to enter the python interactive shell.</li>
<li>Type &#8216;<span style="color: #008000;">import matplotlib</span>&#8216; and hit enter, this will import the matplotlib module.  There should be no output if this works.</li>
<li>Type &#8216;<span style="color: #008000;">print matplotlib.__version__</span>&#8216; and hit enter. This will print the version of matplotlib that is installed, you should see output like &#8216;<span style="color: #808000;">0.99.1.1</span>&#8216;.</li>
<li>Type &#8216;<span style="color: #008000;">exit()</span>&#8216; to quit the python interactive shell.</li>
</ol>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.endlesslycurious.com/2009/12/08/installing-matplotlib-on-snow-leopard-with-macports/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Using SQLite in Python</title>
		<link>http://www.endlesslycurious.com/2009/06/24/using-sqlite-in-python/</link>
		<comments>http://www.endlesslycurious.com/2009/06/24/using-sqlite-in-python/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 09:00:14 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.endlesslycurious.com/?p=1318</guid>
		<description><![CDATA[Python has had support for SQLite built-in since version 2.5.
This is a very convenient pairing as SQLite is an excellent lightweight SQL implementation that I find very useful for a variety of tasks e.g. data mining.  Or any task involving manipulating complex data sets where I&#8217;d otherwise end up resorting to using a full blown [...]]]></description>
			<content:encoded><![CDATA[<p><a title="Python.org" href="http://python.org/">Python</a> has had <a title="PyDocs" href="http://docs.python.org/library/sqlite3.html">support</a> for <a title="SQLite.org" href="http://sqlite.org/">SQLite</a> built-in since version 2.5.</p>
<p>This is a very convenient pairing as SQLite is an excellent lightweight SQL implementation that I find very useful for a variety of tasks e.g. data mining.  Or any task involving manipulating complex data sets where I&#8217;d otherwise end up resorting to using a full blown SQL server like <a href="http://www.mysql.com/">MySQL</a>.</p>
<p>Here is a simple example of using SQLite in Python using it&#8217;s built-in sqlite3 module:</p>
<pre class="brush: python;">
import sqlite3

# craete a connection
con = sqlite3.connect('test.db')

# create a cursor
cur = con.cursor()

# create a test table
cur.execute( &quot;CREATE TABLE testTable (myKey INT, myValue INT)&quot; )

# insert some data
for i in range(0,10):
 cur.execute( &quot;INSERT INTO testTable VALUES ( %d, %d )&quot;%(i,i*i) )

# select the data
for row in cur.execute( &quot;SELECT * FROM testTable&quot; ):
 print row

# destroy (drop) our test table
cur.execute( &quot;DROP TABLE testTable&quot; )

# close the connection
con.close()
</pre>
<p>As you can see Python makes handling SQLite (a C language library) much easier, less error prone, and the resulting code much more compact than SQLite&#8217;s native C.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.endlesslycurious.com/2009/06/24/using-sqlite-in-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby or Python: Round Two!</title>
		<link>http://www.endlesslycurious.com/2008/11/14/ruby-or-python-round-two/</link>
		<comments>http://www.endlesslycurious.com/2008/11/14/ruby-or-python-round-two/#comments</comments>
		<pubDate>Fri, 14 Nov 2008 08:00:58 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.endlesslycurious.com/?p=745</guid>
		<description><![CDATA[Yesterday in my post about web development frameworks, I mentioned I would be revisiting my previous post on whether to learn Python or Ruby.  So this post is a continuation of that earlier discussion.  I&#8217;m bringing up the topic of Python or Ruby again as I have been thinking about web frameworks since watching Cal [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday in my <a href="http://www.endlesslycurious.com/2008/11/13/web-development-frameworks/">post</a> about web development frameworks, I mentioned I would be revisiting my previous <a href="http://www.endlesslycurious.com/2008/10/29/python-or-ruby/">post</a> on whether to learn Python or Ruby.  So this post is a continuation of that earlier discussion.  I&#8217;m bringing up the topic of Python or Ruby again as I have been thinking about web frameworks since watching Cal Henderson&#8217;s &#8216;Why I hate Django&#8217; talk from DjangoCon 2008 at the weekend and then the &#8216;Snakes and Rubies&#8217; <a href="http://www.djangoproject.com/snakesandrubies/">presentation</a>.</p>
<p>The availability of <a href="http://en.wikipedia.org/wiki/Model_View_Controller">MVC</a> oriented web frameworks for Python (<a href="http://www.djangoproject.com/">Django</a>) and Ruby (<a href="http://www.rubyonrails.org/">Ruby on Rails</a>) was not something I had considered when making my earlier decision about which of these two languages to put time into learning.  However now that the idea of writing a new version of this site in one of these new fangled MVC/ORM frameworks has occurred to me, I&#8217;d like to reconsider my earlier decision.  I&#8217;ve done some Google searches on &#8216;Django or Ruby on Rails&#8217; and have been reading through the <a href="http://www.google.ca/search?q=django+or+ruby+on+rails">results</a>.  One of the more interesting blog posts I found on Django, Rails and php (<a href="http://epicserve.com/blog/69/python-and-django-ruby-on-rails-and-php">here)</a> has lead me on to the videos of the &#8216;Snakes and Rubies&#8217; presentations which are very informative and well worth watching (they can be found <a href="http://www.djangoproject.com/snakesandrubies/">here</a>).</p>
<p>So far after watching the Django presentation I must admit I&#8217;m loving a lot of what was demonstrated: automatic administration page generation, built in caching, URL pattern matching and templates which separate content and logic/code sounds ideal.  The automatic generation of an administration interface sounds especially nice as writing an decent administration interface is very time consuming to do correctly.  And these interfaces are not something the end users will generally ever see so it can fell like a lot of effort for a feature that is never appreciated by the general population only by the administrators.  The template system sounds excellent as well as it means graphic/web designers can handle the design of the site without requiring programming knowledge or support.</p>
<p>I&#8217;ve now watched the Ruby presentation too and I have to admit it did not grab me as much as the Django presentation did.  Beautiful code, which seemed to be the main selling point of the presentation is a wonderful thing.  However features like administration interface generation, caching and templates are more attractive to me than being able to use fewer lines of code to do things.</p>
<p>To digress for a moment, I think that my lack of excitement at the concept of beautiful code as it was presented in the video, could be in part to me being mainly a C/C++ programmer: so beautiful code in the sense of code that does a lot of work in a few lines of source code is not something you see very often in C/C++.  In fact in a lot of cases that particular brand of beautiful code is something you would be down right suspicious of in C/C++ but that is perhaps more due to the nonrestrictive nature of C/C++: its lack of hand holding or built in safety as a language.  This lack of safety perhaps drives C/C++ programmers to be more obsessive about understanding what exactly their source code does under the hood to avoid unpleasant surprises later.  This encourages a preference for easy to read and comprehend source code and perhaps promotes suspicion of &#8216;voodoo&#8217; code that does allot of work in a few lines of usually harder to read code.  In short beautiful code is a worthy goal but something I would personally be suspicious of but that is probably more due to my personal C/C++ baggage than any fault in Ruby.</p>
<p>Now back to Ruby on Rails or Django.  Another thing which I had not really considered in my earlier post was which language had the best range of high quality libraries available.  I had assumed that both languages would have a similar range of libraries available but so far my investigations seem to be pointing to Python as having more.  Ruby does not seem to have as many available libraries, unless of course I&#8217;m using the wrong keywords when searching the ruby gems system and if that is actually the definitive library index for Ruby.  This lack of libraries is quite a big deal to me, as I am a big fan of not reinventing the wheel unless it is absolutely necessary, so I like having lots of high quality libraries I can use.  That also speeds up prototyping efforts as it is easier to hook up existing libraries than write the same functionality from scratch again yourself.</p>
<p>In summary when I consider learning Python or Ruby for scripting, rapid prototyping and with added dimension of writing a website with an MVC framework.  I think I would now reverse my decision and learn Python rather than Ruby.  If I was still just thinking about scripting and prototyping with these languages I would consider the two languages evenally matched.  With Python having an advantage with the apparent range and quality of its libraries and Ruby having an advantage with its support of Public/Private class members which I am more comfortable with.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.endlesslycurious.com/2008/11/14/ruby-or-python-round-two/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Web Development Frameworks</title>
		<link>http://www.endlesslycurious.com/2008/11/13/web-development-frameworks/</link>
		<comments>http://www.endlesslycurious.com/2008/11/13/web-development-frameworks/#comments</comments>
		<pubDate>Thu, 13 Nov 2008 08:00:47 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Web Dev]]></category>

		<guid isPermaLink="false">http://www.endlesslycurious.com/?p=738</guid>
		<description><![CDATA[When I created my first website back in 1998 it was purely static HTML that I created with Adobe&#8217;s DreamWeaver application.  Next I discovered dynamic websites built using php and MySQL databases, so my next few sites were all written in php and accessing a MySQL database for the content.  I have to confess that [...]]]></description>
			<content:encoded><![CDATA[<p>When I created my first website back in 1998 it was purely static <a href="http://en.wikipedia.org/wiki/HTML">HTML</a> that I created with Adobe&#8217;s <a href="http://www.adobe.com/products/dreamweaver/">DreamWeaver</a> application.  Next I discovered dynamic websites built using <a href="http://www.php.net/">php</a> and <a href="http://www.mysql.com/">MySQL</a> databases, so my next few sites were all written in php and accessing a MySQL database for the content.  I have to confess that these initial dynamic sites were written in the worst style possible: inline php in the HTML and spaghetti php, all things that <a href="http://www.tbray.org/ongoing/When/200x/2006/02/17/PHP">invoke</a> <a href="http://www.codinghorror.com/blog/archives/001119.html">horror</a> in other programmers.</p>
<p>It was not until I started helping out with <a href="http://www.rockclimbing.com/">RockClimbing.com</a> for a brief period which exposed me to a large scale php project supporting many thousands of users.  With its advanced language usage, separation of code, content and layout with <a href="http://www.smarty.net/">smarty</a> templates, advanced caching and high performance database queries (one of the developers ended up working for MySQL iirc) it was beyond anything I had seen before.  All this opened my eyes to how to architect a site in php correctly and that it could be a truly elegant language to work with and I am not alone in this <a href="http://www.sitepoint.com/blogs/2006/02/21/a-pro-php-rant/">feeling</a>.  Then for a period of several years my personal site fell into disuse as I was distracted by work and life from doing any active web development.</p>
<p>This year I decided to start this blog on a new domain name and start writing about software engineering and programming.  My choice of blog engine?  <a href="http://wordpress.org/">WordPress</a>: which is a php based blogging engine which runs with MySQL as its database.  I found myself tweaking my WordPress installation almost immediately and I found it easy enough to do as php was already familiar to me.  In fact I&#8217;ve been tweaking so much that I&#8217;ve now set-up a Perforce server at home so I can track, audit and keep a log of my changes.  As I&#8217;ve explored the WordPress code base over the months, I&#8217;ve noticed that it is not the prettiest of code in place and again I&#8217;m <a href="http://mgeisler.net/2005/05/wordpress-code-quality/">not</a> <a href="http://www.codinghorror.com/blog/archives/001105.html">alone</a> <a href="http://codeutopia.net/blog/2008/01/26/impressions-on-wordpress/">in</a> <a href="http://twitter.com/codinghorror/statuses/994018417">noticing</a> <a href="http://talideon.com/weblog/2006/06/bad-wordpress.cfm">this</a>.</p>
<p>Please don&#8217;t misunderstand me, I like WordPress <em>a lot</em>, it has made setting up and running this blog <em>trivial</em>, especially when compared with writing my own blog engine from scratch. I&#8217;m simply commenting on my perception of the quality of the underlying source code, something I think all programmers do especially with things they&#8217;ve written (although I did not write WordPress, I just modified it).  It would be nice to see a code tidy up and the introduction of templates and caching to the core engine, but that is a big job to undertake and I don&#8217;t think I have the required amount of spare time to achieve it myself.</p>
<p>All this has got me thinking about the recent(ish) upsurge in the number of web development frameworks that are embracing things like <a href="http://en.wikipedia.org/wiki/Object-relational_mapping">Object Relational Mapping</a> (ORM) and development models like the <a href="http://en.wikipedia.org/wiki/Model_View_Controller">Model-View-Controller</a> (MVC) pattern.  The two programming languages that seem to be leading this charge are <a href="http://www.python.org/">Python</a> with <a href="http://www.djangoproject.com/">DJango</a> and <a href="http://www.ruby-lang.org/en/">Ruby</a> with its <a href="http://www.rubyonrails.org/">Rails</a> framework, no doubt there are other frameworks in other languages too (e.g. <a href="http://www.asp.net/mvc/">ASP MVC</a>, php&#8217;s <a href="http://www.symfony-project.org/">symfony</a> framework).  The increase in popularity of these frameworks with built in template engines and abstraction of content from layout and logic via MVC are making me consider setting out on the path of writing my own personal blog engine again.</p>
<p>Mostly writing my own blog engine is a way to learn and embrace these new technologies and concepts and also a chance to see what all the fuss is about.  This would mean leaving the cosy comfort of my WordPress armchair, so most likely this experiment will become something I initially develop in a test <a href="http://en.wikipedia.org/wiki/Sandbox_(software_development)">sandbox</a> at home until I have something that is worthy of publishing online.  My decision now is what language and framework to use.  Do I stick to php with Smarty and MySQL or do I try something new like Python&#8217;s Django or Ruby on Rails?  Right now I&#8217;m tempted by either Python or Ruby for reasons I will talk about in a post tomorrow.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.endlesslycurious.com/2008/11/13/web-development-frameworks/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
