<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>PaulBarry.com - Python is Weird</title>
  <subtitle type="html">My thoughts, ideas, questions and concerns on technology, sports, music and life</subtitle>
  <id>tag:paulbarry.com,2007:Paulbarry.com</id>
  <generator uri="http://www.paulbarry.com" version="3.0">PaulBarry.com</generator>
  <link href="http://paulbarry.com/xml/atom/article/122/feed.xml" rel="self" type="application/atom+xml"/>
  <link href="http://paulbarry.com/articles/2006/09/20/python-is-weird" rel="alternate" type="text/html"/>

  <updated>2008-11-03T16:11:41-05:00</updated>
  <entry>
    <author>
      <name>Paul Barry</name>
      <email>mail@paulbarry.com</email>
    </author>
    <id>urn:uuid:82df2b68-704b-4958-869f-039347425b7f</id>

    <published>2006-09-20T22:09:14-04:00</published>
    <updated>2006-09-20T22:09:14-04:00</updated>
    <title type="html">Python is Weird</title>
    <link href="http://paulbarry.com/articles/2006/09/20/python-is-weird" rel="alternate" type="text/html"/>

    <category term="technology" scheme="http://paulbarry.com/articles/category/technology" label="Technology"/>
        <category term="Rails" scheme="http://paulbarry.com/articles/tag/rails"/>
    <category term="Python" scheme="http://paulbarry.com/articles/tag/python"/>
    <category term="Django" scheme="http://paulbarry.com/articles/tag/django"/>
    <category term="Ruby" scheme="http://paulbarry.com/articles/tag/ruby"/>
    <category term="Java" scheme="http://paulbarry.com/articles/tag/java"/>
        <summary type="html">&lt;p&gt;I&apos;ve heard some good things about the &lt;a href=&quot;http://www.djangoproject.com/&quot;&gt;Django framework&lt;/a&gt;.  One thing that as me interested in Django is that the way it works in general is you define your domain model in code, in Python objects, and Django figures out how to build a database for you.  Conceptually, I like this idea better than &lt;a href=&quot;http://www.rubyonrails.org/&quot;&gt;Ruby on Rails&lt;/a&gt;, where you define your domain model in the database, and then rails generates objects for you at runtime based on the database metadata.  Also, you run it my installing mod_python in apache.  Again, compared to rails with apache, FCGI/SCGI, lighttpd, mongrel, etc..., I don&apos;t know, let&apos;s just say I have found the process of setting up a rails production web/app server challenging.  I haven&apos;t done it for Django yet, we&apos;ll see.  Should be a small memory footprint too, making it easy to run multiple apps in my 192MB virtual server webhost.&lt;/p&gt;

&lt;p&gt;But one thing I want to comment on now is that I find Python to be weird.  Maybe this is because I have done most of my programming in Java, but when I started to learn Ruby, everything in Ruby just made sense, without Java&apos;s stupidity, such as NullPointerExceptions and primatives.  I&apos;ve soured on rails recently, but I miss Ruby.  The language is succinct and powerful, it almost feels like writing psuedo code, except that it actually works.&lt;/p&gt;

&lt;p&gt;Anyway, let me just give a few examples of python weirdness.  But before I do, let me say this.  I don&apos;t know python well at all.  Consider these statements to be my first impressions of Python.  I&apos;m in no way stating that python is poor language due to these oddities, they just strike me as odd and I feel the need to express it.  So, on with the weirdness:&lt;/p&gt;

&lt;p&gt;So to get started, I started reading the &lt;a href=&quot;http://www.djangoproject.com/documentation/install/&quot;&gt;Django install guide&lt;/a&gt;.  I noticed I needed python 2.3 or higher.  Fair enough, so python 2.5 is the latest, so I installed that.&lt;/p&gt;

&lt;p&gt;The next requirement is for MySQLdb.  It says it works with python 2.3-2.4, doesn&apos;t say anything about 2.5.  I decide to install python 2.4 to be safe.  So just deciding which version of python to use is a little bit of a struggle.&lt;/p&gt;

&lt;p&gt;So now I have python 2.4 and MySQLdb.  I want to try and do something simple to verify it is working.  I find an example in the docs:&lt;/p&gt;

&lt;pre&gt;import MySQLdb
db=MySQLdb.connect(passwd=&quot;moonpie&quot;,db=&quot;thangs&quot;)

c=db.cursor()
max_price=5
c.execute(&quot;&quot;&quot;SELECT spam, eggs, sausage FROM breakfast
          WHERE price &lt; %s&quot;&quot;&quot;, (max_price,))&lt;/pre&gt;

&lt;p&gt;What&apos;s with the 3 quotes?  Anyway, let&apos;s give it a try.  First, I add c:python24in to my path, fire up a command prompt, and enter &quot;python&quot; in hopes of getting an interactive shell.  Python isn&apos;t found.  Why not, because the python executables aren&apos;t in c:python24in, they are in c:python24.  Ok fine, I fix my path, but I decide to use the IDLE GUI instead. I try to enter a query, but I make a typo.  I press the up arrow, but it doesn&apos;t bring up my previous command.  I re-type it and get it right this time.  The query is:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;select count(*) from users&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This returns 9 when I execute the query in mysql.  What does Python return?&lt;/p&gt;

&lt;p&gt;&lt;code&gt;1L&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;1L?  What is that?  Again, I am naive when it comes to python, this is not a fair criticism of Python, I have done very little to learn the language at this point, I just trying to illustrate a point.  I know Java well.  When I started learning Ruby, from the start, everything just worked as you expected it would.  As I look into Python, I find one oddity after another.  I&apos;m sure if you know Python well you will consider many of the things in Java odd, so I&apos;m just going to consider all of these things first impressions and move on to learn more about the language and give it a fair chance.  But Python is still Weird.&lt;/p&gt;
</summary>
    <content type="html">&lt;p&gt;I&apos;ve heard some good things about the &lt;a href=&quot;http://www.djangoproject.com/&quot;&gt;Django framework&lt;/a&gt;.  One thing that as me interested in Django is that the way it works in general is you define your domain model in code, in Python objects, and Django figures out how to build a database for you.  Conceptually, I like this idea better than &lt;a href=&quot;http://www.rubyonrails.org/&quot;&gt;Ruby on Rails&lt;/a&gt;, where you define your domain model in the database, and then rails generates objects for you at runtime based on the database metadata.  Also, you run it my installing mod_python in apache.  Again, compared to rails with apache, FCGI/SCGI, lighttpd, mongrel, etc..., I don&apos;t know, let&apos;s just say I have found the process of setting up a rails production web/app server challenging.  I haven&apos;t done it for Django yet, we&apos;ll see.  Should be a small memory footprint too, making it easy to run multiple apps in my 192MB virtual server webhost.&lt;/p&gt;

&lt;p&gt;But one thing I want to comment on now is that I find Python to be weird.  Maybe this is because I have done most of my programming in Java, but when I started to learn Ruby, everything in Ruby just made sense, without Java&apos;s stupidity, such as NullPointerExceptions and primatives.  I&apos;ve soured on rails recently, but I miss Ruby.  The language is succinct and powerful, it almost feels like writing psuedo code, except that it actually works.&lt;/p&gt;

&lt;p&gt;Anyway, let me just give a few examples of python weirdness.  But before I do, let me say this.  I don&apos;t know python well at all.  Consider these statements to be my first impressions of Python.  I&apos;m in no way stating that python is poor language due to these oddities, they just strike me as odd and I feel the need to express it.  So, on with the weirdness:&lt;/p&gt;

&lt;p&gt;So to get started, I started reading the &lt;a href=&quot;http://www.djangoproject.com/documentation/install/&quot;&gt;Django install guide&lt;/a&gt;.  I noticed I needed python 2.3 or higher.  Fair enough, so python 2.5 is the latest, so I installed that.&lt;/p&gt;

&lt;p&gt;The next requirement is for MySQLdb.  It says it works with python 2.3-2.4, doesn&apos;t say anything about 2.5.  I decide to install python 2.4 to be safe.  So just deciding which version of python to use is a little bit of a struggle.&lt;/p&gt;

&lt;p&gt;So now I have python 2.4 and MySQLdb.  I want to try and do something simple to verify it is working.  I find an example in the docs:&lt;/p&gt;

&lt;pre&gt;import MySQLdb
db=MySQLdb.connect(passwd=&quot;moonpie&quot;,db=&quot;thangs&quot;)

c=db.cursor()
max_price=5
c.execute(&quot;&quot;&quot;SELECT spam, eggs, sausage FROM breakfast
          WHERE price &lt; %s&quot;&quot;&quot;, (max_price,))&lt;/pre&gt;

&lt;p&gt;What&apos;s with the 3 quotes?  Anyway, let&apos;s give it a try.  First, I add c:python24in to my path, fire up a command prompt, and enter &quot;python&quot; in hopes of getting an interactive shell.  Python isn&apos;t found.  Why not, because the python executables aren&apos;t in c:python24in, they are in c:python24.  Ok fine, I fix my path, but I decide to use the IDLE GUI instead. I try to enter a query, but I make a typo.  I press the up arrow, but it doesn&apos;t bring up my previous command.  I re-type it and get it right this time.  The query is:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;select count(*) from users&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This returns 9 when I execute the query in mysql.  What does Python return?&lt;/p&gt;

&lt;p&gt;&lt;code&gt;1L&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;1L?  What is that?  Again, I am naive when it comes to python, this is not a fair criticism of Python, I have done very little to learn the language at this point, I just trying to illustrate a point.  I know Java well.  When I started learning Ruby, from the start, everything just worked as you expected it would.  As I look into Python, I find one oddity after another.  I&apos;m sure if you know Python well you will consider many of the things in Java odd, so I&apos;m just going to consider all of these things first impressions and move on to learn more about the language and give it a fair chance.  But Python is still Weird.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <author>
      <name>David Sissitka</name>
    </author>
    <id>urn:uuid:6301458d-2171-4aea-ac46-152ed0b11574</id>
    <published>2006-09-21T00:10:14-04:00</published>
    <updated>2006-09-21T00:10:14-04:00</updated>
    <title type="html">Comment on "Python is Weird" by David Sissitka</title>
    <link href="http://paulbarry.com/articles/2006/09/20/python-is-weird#comment-123" rel="alternate" type="text/html"/>
    <content type="html">The Rails equivalent of Django&apos;s models would be migrations (And models, for custom functions and the like.). As for Python, triple quotes delimit a string that covers multiple lines. I believe the query returned 1L because there was one result set, and t</content>
  </entry>
  <entry>
    <author>
      <name>Duncan McGreggor</name>
    </author>
    <id>urn:uuid:154f370d-ca36-4f69-99b2-29e4a02d7790</id>
    <published>2006-09-21T04:15:57-04:00</published>
    <updated>2006-09-21T04:15:57-04:00</updated>
    <title type="html">Comment on "Python is Weird" by Duncan McGreggor</title>
    <link href="http://paulbarry.com/articles/2006/09/20/python-is-weird#comment-127" rel="alternate" type="text/html"/>
    <content type="html">Hey Paul -- gald to see you venturing into python :-)&lt;br/&gt;&lt;br/&gt;Some notes:&lt;br/&gt;&lt;br/&gt;1) Python 2.5 was released literally a few days ago, thus no mention of it in docs.&lt;br/&gt;&lt;br/&gt;2) The use of three quotes is for multi-line quoting. A new line inside a single quote (either &amp;quot; or &apos;)</content>
  </entry>
  <entry>
    <author>
      <name>Brandon Corfman</name>
    </author>
    <id>urn:uuid:adcb247f-9ae4-4ec9-b074-cc77dcc3fd18</id>
    <published>2006-09-21T08:33:33-04:00</published>
    <updated>2006-09-21T08:33:33-04:00</updated>
    <title type="html">Comment on "Python is Weird" by Brandon Corfman</title>
    <link href="http://paulbarry.com/articles/2006/09/20/python-is-weird#comment-128" rel="alternate" type="text/html"/>
    <content type="html">I&apos;d start with &amp;quot;Learning Python&amp;quot; or &amp;quot;Dive Into Python&amp;quot; for easing yourself into the language. &lt;br/&gt;&lt;br/&gt;As the others have pointed out, the Django snippet assumes knowledge of tuples, multi-line strings and long integer syntax. It would be like meeting Ruby for t</content>
  </entry>
  <entry>
    <author>
      <name>Paul</name>
    </author>
    <id>urn:uuid:7c1e51bd-44ea-4736-a5b7-ffae0ca562c4</id>
    <published>2006-09-21T10:03:45-04:00</published>
    <updated>2006-09-21T10:03:45-04:00</updated>
    <title type="html">Comment on "Python is Weird" by Paul</title>
    <link href="http://paulbarry.com/articles/2006/09/20/python-is-weird#comment-129" rel="alternate" type="text/html"/>
    <content type="html">Hey guys, thanks for the feedback.&lt;br/&gt;&lt;br/&gt;David:&lt;br/&gt;&lt;br/&gt; - Migrations aren&apos;t actual objects that you use.  Migrations are simply SQL DDL statements written in Ruby to abstract the database specific syntax.  They also provide a way to keep track of individual chan</content>
  </entry>
  <entry>
    <author>
      <name>David Sissitka</name>
    </author>
    <id>urn:uuid:58967615-18e4-4a87-8dcc-c0a6f00abfbd</id>
    <published>2006-09-21T12:49:28-04:00</published>
    <updated>2006-09-21T12:49:28-04:00</updated>
    <title type="html">Comment on "Python is Weird" by David Sissitka</title>
    <link href="http://paulbarry.com/articles/2006/09/20/python-is-weird#comment-130" rel="alternate" type="text/html"/>
    <content type="html">I wasn&apos;t very clear about the whole Django models thing. There really isn&apos;t a one to one conversion, but if you piece together a few of the features present in Rails you can get pretty close. I&apos;m new to Python myself, but it looks like 1L is a boolean val</content>
  </entry>
  <entry>
    <author>
      <name>David Sissitka</name>
    </author>
    <id>urn:uuid:74eacfea-2d8e-4fee-a3d3-a73d854735a6</id>
    <published>2006-09-21T12:57:50-04:00</published>
    <updated>2006-09-21T12:57:50-04:00</updated>
    <title type="html">Comment on "Python is Weird" by David Sissitka</title>
    <link href="http://paulbarry.com/articles/2006/09/20/python-is-weird#comment-131" rel="alternate" type="text/html"/>
    <content type="html">As for editors, I use Komodo IDE (See: http://www.activestate.com/). It gets bonus points for supporting Ruby.</content>
  </entry>
  <entry>
    <author>
      <name>Duncan McGreggor</name>
    </author>
    <id>urn:uuid:30f4c394-145c-4e6a-a4ba-e53f27c3e636</id>
    <published>2006-09-21T18:20:05-04:00</published>
    <updated>2006-09-21T18:20:05-04:00</updated>
    <title type="html">Comment on "Python is Weird" by Duncan McGreggor</title>
    <link href="http://paulbarry.com/articles/2006/09/20/python-is-weird#comment-133" rel="alternate" type="text/html"/>
    <content type="html">David, the 1L may *represent* a boolean (I have no idea what the mysql lib is doing; I can&apos;t remember the last time I used mysql or the python bindings for it... long live efficient ORMs), but it really is a long int :-)&lt;br/&gt;&lt;br/&gt;Paul, I&apos;m hardly the person to as</content>
  </entry>
  <entry>
    <author>
      <name>Paul</name>
    </author>
    <id>urn:uuid:dedbfbfe-ff67-4e32-b291-42ccb9dd7146</id>
    <published>2006-09-21T18:38:17-04:00</published>
    <updated>2006-09-21T18:38:17-04:00</updated>
    <title type="html">Comment on "Python is Weird" by Paul</title>
    <link href="http://paulbarry.com/articles/2006/09/20/python-is-weird#comment-134" rel="alternate" type="text/html"/>
    <content type="html">Duncan,&lt;br/&gt;&lt;br/&gt;I understand what you are saying about IDEs.  The things I absolutely need out of an IDE/Editor is:&lt;br/&gt;&lt;br/&gt;1.  The ability to run unit tests and see the results from within the editor.  You do write unit tests in python/django apps, right? :)&lt;br/&gt;&lt;br/&gt;2.</content>
  </entry>
  <entry>
    <author>
      <name>Duncan McGreggor</name>
    </author>
    <id>urn:uuid:def4ee20-5db0-457b-98bd-10acfe21e665</id>
    <published>2006-09-21T19:17:26-04:00</published>
    <updated>2006-09-21T19:17:26-04:00</updated>
    <title type="html">Comment on "Python is Weird" by Duncan McGreggor</title>
    <link href="http://paulbarry.com/articles/2006/09/20/python-is-weird#comment-135" rel="alternate" type="text/html"/>
    <content type="html">Hey Paul,&lt;br/&gt;&lt;br/&gt;1. Do you know about doctests in python? They are freaking awesome, and if I&apos;m not doing Twisted python work, I put all my unit tests in doctests -- python code embedded in doc strings (you can copy and paste from the python interpreter, as it </content>
  </entry>
  <entry>
    <author>
      <name>Brandon Corfman</name>
    </author>
    <id>urn:uuid:cdfd9eb7-1e89-4686-bdf6-fdc3106ffbd9</id>
    <published>2006-09-22T11:06:42-04:00</published>
    <updated>2006-09-22T11:06:42-04:00</updated>
    <title type="html">Comment on "Python is Weird" by Brandon Corfman</title>
    <link href="http://paulbarry.com/articles/2006/09/20/python-is-weird#comment-137" rel="alternate" type="text/html"/>
    <content type="html">Currently you can try out Komodo 4.0 for free since it&apos;s in alpha (but still stable -- I&apos;ve used it):&lt;br/&gt;http://activestate.com/store/beta/register.plex?id=komodo&lt;br/&gt;&lt;br/&gt;Wingware also has a free 30-day trial:&lt;br/&gt;http://wingware.com/wingide/trial&lt;br/&gt;&lt;br/&gt;A review of 6 Python</content>
  </entry>
  <entry>
    <author>
      <name>Brandon Corfman</name>
    </author>
    <id>urn:uuid:18c07b5e-f44a-479a-b1a1-80136b78c830</id>
    <published>2006-09-22T11:11:20-04:00</published>
    <updated>2006-09-22T11:11:20-04:00</updated>
    <title type="html">Comment on "Python is Weird" by Brandon Corfman</title>
    <link href="http://paulbarry.com/articles/2006/09/20/python-is-weird#comment-138" rel="alternate" type="text/html"/>
    <content type="html">P.S. I just read more of your blog and realized you live close to Baltimore. I&apos;m in NE Maryland, in Havre de Grace. Small world. :)</content>
  </entry>
  <entry>
    <author>
      <name>Lukasz</name>
    </author>
    <id>urn:uuid:dc23f4b2-187a-45ce-97b9-93795461b8d0</id>
    <published>2006-09-25T08:52:36-04:00</published>
    <updated>2006-09-25T08:52:36-04:00</updated>
    <title type="html">Comment on "Python is Weird" by Lukasz</title>
    <link href="http://paulbarry.com/articles/2006/09/20/python-is-weird#comment-139" rel="alternate" type="text/html"/>
    <content type="html">`c.execute(..)` returns 1L which is number of rows returned by SQL statement (this is specific for MySQLdb library). If You would like to get value of SQL `count(*)` You must use:&lt;br/&gt;&lt;br/&gt;        row = c.fetchone()&lt;br/&gt;        count = row[0]&lt;br/&gt;&lt;br/&gt;(This value is handy, i</content>
  </entry>
  <entry>
    <author>
      <name>Flip</name>
    </author>
    <id>urn:uuid:a042d75c-8d49-4a91-92b0-be3a7223e8f2</id>
    <published>2007-02-06T10:30:50-05:00</published>
    <updated>2007-02-06T10:30:50-05:00</updated>
    <title type="html">Comment on "Python is Weird" by Flip</title>
    <link href="http://paulbarry.com/articles/2006/09/20/python-is-weird#comment-4711" rel="alternate" type="text/html"/>
    <content type="html">Python has some neat class type stuff.  For example, a unicode string would be u&amp;quot;this is a unicode string.&amp;quot;  Similarly, 1L implies 1 (like, the number) returned as a Long. It&apos;s Django trying to make sure nothing breaks when you get an ID of 49582044506 and try to int() that sucker.&lt;br/&gt;&lt;br/&gt;Best,&lt;br/&gt;Flip</content>
  </entry>
  </feed>