Tuesday, June 25, 2013


Last year, I resolved to learn a little bit about Python to see whether its worth incorporating into my workflow. Since I'm now involved in a project where Python is being used to do some basic scripting, I decided the time had come to teach myself the basics. I blocked off a day and a half to pursue this, and here's what I came up with...

First off, here is the original article that sparked my interest in Python. Definitely worth a read.

Next, I needed Python installed. It was already installed on my Mac but I went ahead and followed some advice to upgrade to a version from python.org. I'm using

  • Python 2.7.5 :: Anaconda 1.6.0 (x86_64)
Next, I needed a tutorial to get started. I found an excellent tutorial posted by someone at Google. I didn't even bother with the videos - I just read the text and performed the exercises (some of which were really challenging). The tutorial is here:
I also looked into another neat one that someone suggested to me. I really liked the user interface. The examples weren't nearly as challenging as the Google site...
Super, so having worked through those tutorials, I felt like I had my head wrapped around Python's basics. Its a pretty neat language, very good for scripting, very good hooks to get data from online. I successfully used Python to pull data from various web pages and to access my email (via imap). Its an interpreted language so you don't have to fight with a compiler, and the interpreter is pretty forgiving. I used a standard text editor (Textwrangler) and ran the interpreter from the terminal command line.

There are a number of add-ons that make Python really powerful, it seems. Two of the most exciting are NumPy and SciPy. NumPy is a package that adds support for n-dimensional matrix manipulation (a la Matlab). SciPy adds all the functions you need for serious scientific computing - it uses the NumPy data types. You can download them both from http://wiki.scipy.org/. Finally, you need one more tool to create all your beautiful plots and figures. Matplotlib is the best package out there and produces some very nice images - it works seamlessly with SciPy and NumPy. You can download it from http://matplotlib.org/downloads.html. Incidentally, this page gives an excellent comparison on the differences between NumPy/SciPy and Matlab.

I also downloaded an optional tool called iPython. iPython gives you access to a number of tools but most importantly an interactive interpreter that is very close to the experience you get from Maltab's command line. I got iPython by downloading the Anaconda package.

Finally, it appears that Python has the ability to create "executables" that you can distribute to users who don't have Python installed on their machines. There are a number of packages available for this but it seems the best is PyInstaller (http://www.pyinstaller.org/). I haven't had a chance to try this out in much detail but I'm optimistic - one of my biggest problems with Matlab is that distributing a stand-alone executable is a complete nightmare for the end user.

And in case anyone's interested, this is the page that showed me how to hack my email from Python.

So ... good for me, I finally got around to learning a software tool that's been mature for over a decade now :) But better late to the party than never. Very impressive stuff. I think for me, I see a lot of possibility for this to displace Matlab but I'm already so entrenched with Matlab that it'd be pretty wasteful for me to switch completely at this point. Starting a new project from scratch in Python would mean a lot of time scrambling up the learning curve. Still, I'm enjoying this new language and I'll probably mess around with it more in the near future, especially if it winds up being valuable to my project.

No comments:

Post a Comment