Life with Python
I have a confession to make — despite writing a well-known tutorial for Supermongo, I actually use Python for most of my work nowadays. Python can have a steep learning curve, particularly if you’re inexperienced with object-oriented programming. And then there’s matplotlib, whose documentation assumes a broad knowledge of Matlab.
Hence, here is an introduction to life with Python, for astronomers. This is not meant to be a comprehensive guide to Python — that’s what the Python Tutorial is for. It is meant to help you get started with Python if you’re switching over from IDL or Supermongo or Fortran. It should also clarify the matplotlib documentation where appropriate.
Getting Started
Before you start, you should have a recent version of Python (2.5 or later) installed on your machine. Then, you should install Numpy, SciPy (which uses Numpy arrays), and matplotlib. There is a lot of example code at the matplotlib site, which I have found to be extremely useful.
The interactive Python shell IPython is nice to have. I usually just run scripts from the command line, but the shell is good for debugging.
Once a package is installed on your machine, importing it is simple. There are several ways to import, but for the sake of clarity I prefer using the syntax import package as pkg. Then every function in package is referred to as pkg.func. For numpy, the common shorthand is np. For matplotlib.pyplot, the common shorthand is plt. However, for the sake of clarity, when I first refer to a numpy function I will use numpy.func, not np.func.
First up, Data in Python! Both the structure of and reading in of.