I have never gotten very good at any of the popular shell scripting languages. Over the years, I’ve dabbled in Bourne sh scripts, Perl, awk, and sed. I was never one of those magical guys who could make anything happen in a few seconds. But I’ve always wanted that to change.
I’ve decided to learn Python. I want a fast-acting Swiss Army Knife at my disposal for splicing together the loose ends of my computer life.
Why Python? I don’t know it well enough to really sing its praises, but a number of influences caused me to veer towards this language (as opposed to say, improving my Perl or picking up Ruby):
- A Killer App. NodeBox was the catalyst for this whole pursuit, though it has nothing to do with productivity, per se. I downloaded NodeBox on the recommendation of a friend, and was instantly blown away that such a tool exists at all. NodeBox makes it easy to programatically produce graphics on the Mac, exploiting the Quartz graphics capabilities of the system. Python happens to be the language for driving these amazing dynamic documents.
- A Good Reputation. I started dropping Python references among groups of programmer nerds who I respect. Almost universally people either didn’t respond (people like me), or else raved about how great it was. About the only thing I ever hear people complain about with Python is its strict indentation rules. Hey. I’m a C programmer, but I have style. Indentation is OK by me.
- Support From “The Man”. I’ll admit it, I am more likely to embrace something if Apple does it first. It’s just easier to get involved and stay involved with a technology when you know that there will be value-added by the most influential company in your little neck of the tech woods. Apple has included Python with Mac OS X as a standard part of the system, and even gone so far as to provide special Python bindings in frameworks like Quartz to facilitate the above-mentioned scripting tricks. I can embrace this language without worrying that its functionality on the Mac will suddenly disappear.
- A Decent Tutorial. The biggest roadblock to learning for me is finding the start of a good path. If there is an incremental process I can follow to get better at something and eventually “know it,” then it’s much easier to tackle. The author of Python himself, Guido van Rossum, provides a short-and-sweet tutorial that made it easy for me to get to know Python.
I have a little trick with these “short chapters” tutorials. I keep a bookmark to the “next chapter” in my Safari bookmarks bar, and add reading it to my ToDo list for the following day. When I finish the chapter, I update the toolbar bookmark and wait until the next day. That way the learning is never overwhelming – just a few minutes aday, and it still only takes me a couple weeks to get through the whole tutorial.
This trick is OK, but while I was taking this tutorial, I got annoyed by having to constantly flash back and forth between the web page and my Terminal window. The Python tutorial introduces you to ideas that, if you’re anything like me, you immediately want to try out in the interactive shell. I decided to take a cue from Michael McCracken, who recently produced and distributed a dumbed down web browser just for reading Gmail.
Learn Python is a simple Mac OS X application (GNU License, source included) that puts a web browser and terminal window into one application. The web browser points at the aforementioned Python tutorial on the web, and it remembers the last URL you went to, so you can trust it to remember which chapter you were at when you last quit.
It’s a Python-Tutorial Browsing Machine!
By almost every possible measurement, this project was a “waste of time.” But sometimes you’ve got to make the software you wish existed, just so you know it does. I rationalize the time as well-spent since it sets me up to easily crank out one-offs of a similar vein as I find a use for them. If I was really bored I would probably have added “value added” buttons to the UI for specifically navigating the document structure (e.g. next chapter, etc). But I think I’m done for now. Hopefully most of the bugs are ironed out.
I hope some of you will get some use out of this extremely narrow piece of work. At least it might encourage you to learn Python!
PS: Unhappy with the default version of Python that gets launched? Or wish you could use the tool as a ruby or shell scripting or whatever tool? I haven’t put any preferences in this application, but it would be easy enough to hack the sources. If you aren’t feeling up to hacking the sources, or don’t have the tools handy, you can specifically override the path of the launched tool by editing the file “Localizable.strings” in “Learn Python.app/Contents/Resources/English.lproj/”. Inside this file, change the line:
"/usr/bin/python" = "/usr/bin/python";
That will tell the application to use zsh instead of python. Replace the “/bin/zsh” with whatever you want.
Update (June 3, 2006): The download has been updated to version 1.0.3, which now defaults to a left-right orientation for the web and python shell panes. The setting can be changed back to top-bottom through the preferences dialog.
Update (June 4, 2006): Rodney Ramdas posted a modified version of the application that is targeted at learning Ruby, instead. I’ll probably use it to tackle Ruby, next!