Python Tips

Setting up

If you are new to Python, we're recommending that you install the Anaconda distribution on your computer. If you already are up and running and happy with some other Python install, that's fine too, but you will want to make sure that astropy is installed (Anaconda installs/updates astropy automatically).

Here is the general documentation for the various packages included in Anaconda.


For writing/debugging python code, I have also found using the Spyder environment to be helpful.

Getting help

First of all, try python inline help. For example, help on the scatter command can be obtained by saying help(plt.scatter) (presuming you've already loaded the pyplot package, i.e. import matplotlib.pyplot as plt)

Second, check some online tutorials/references, such as:
Third (or maybe first), try THE GOOGLE. For example, if I want to figure out how to fit a curve to data using python, I'll just google fit curve to data python. Or if I have a bizarre error message that I don't understand, I'll google <bizarre error message> python. adding astropy to the search will often give you astro-specific results as well, which can be particularly helpful. You may have to poke around with the results of those searches to find the best answer, but it usually works out.

Fourth, ask your classmates, or Aaron, or me. I put this last not because we are reluctant to help -- we're happy to do so! -- but rather because the first three things are available to you 24/7 and give immediate (although admittedly not always helpful) responses.


Code snippets

As the need/demand arises, I'll put short cut-n-paste code snippets here for common tasks. If they are helpful, feel free to use them.
  1. Aaron's universal script to read an ascii file of data columns: readfile.py





What other things would be useful? Let me know......