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, although if you are used to using jupyter notebooks, that works just fine as well.

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 me. I put myself last not because I'm reluctant to help -- I'm 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.