Adventures in Python
I've decided to spend some time learning how to program, and as I encounter problems (and, hopefully, solve them!) I'll drop notes here on my blog in case they help others. Plus this has the added benefit of giving my developer friends a steady stream of entertainment....! And finally, in the style of Julie Starr's TiddlerToddler, it may even provide an interesting beginner's insight for those who are creating or updating documentation.
Why learn to program? Well, because it looks like fun. I've enjoyed working with developers for years now, and while I've dabbled in HTML from time to time, I haven't taken it any further than that. In terms of choosing a language to program in, I really wanted to get building things quickly, so I've plumped for Python, as a route towards using Django. I often hear Python and Django being referred to as a fun and quick route to build quality apps. So let's see how we go.
My starting point has been Alan Gould's Learning to Program guide. I should pause here and say, from my experience working with the TiddlyWiki community, that creating this kind of guide is incredibly time consuming and rarely gets the appreciation it deserves - and its free! So I'd like to start by putting my thanks and appreciation firmly on the record. Thanks, Alan!
It's been a great guide so far, but I came across two problems which I'd like to document here. I'm using Mac OS X (toggling between Leopard on my iMac and Snow Leopard on my Macbook Air), which has Python installed by default, but this isn't the most up to date version. I wanted the most recent version so that my new skills would be as relevant as possible, and the most stable release is v3.1.2 - so I went ahead and downloaded this (it's just a .dmg file, containing an .mpkg file - simple to install).
But for the life of me when I went back to the terminal, and typed "python", the old version kept coming up like this:
It launches Python 2.5.1. I even tried explicitly ticking the "Shell Profile Updater" option during installation - it made no difference. I even tried Google, but had little luck. At this stage I was getting hugely frustrated that I couldn't get over this first hurdle, so I sent out a message on Twitter and was amazed to get help within seconds from Victor Miclovich:
Victor, you are a legend - thank you! And you've inadvertently proved out my assumptions about how helpful the Python community is!
(Incidentally, I've found you don't need the dollar sign - just typing python3 works too)
I also encountered a second problem. Alan's tutorial presents the option between using the terminal (which my colleagues generally favour) or IDLE - an integrated developer environment, which came with Python. Well, the terminal wasn't really working out for me at that point, so I tried IDLE, and followed a link from Alan's tutorial to this IDLE help page.
But when I tried the "Hello world" example, I kept getting a syntax error as follows:
Fortunately, this one was easier to solve. It turns out that Python 3 requires a different syntax from Python 2. Instead of:
print "Hello world"
I needed to type:
print ("Hello world")
Success! (this shows the terminal again, though it worked in IDLE too)
OK....I'm easily pleased, I know!
So..this could be the start of an interesting journey. I can't help thinking about Nicole Lazarro's game theory talks at SXSW and Supernova last year. She talks about "hard fun" - the notion that people are willing to spend a certain amount of time being frustrated in return for the elation of a breakthrough (this applies to games such as Halo, too). So, let's see how long I can keep this up...