Experimental Data Analysis Lab

PHYS 391 - Fall 2020
Python Information

Updated Sunday September 13, 2020

Overview

Python is a widely used system in the sciences for performing computation, data analysis, and data visualization. We will only scratch the surface of what python can do, but getting some hands-on experience with this powerful tool is one of the main goals of PHYS 391. Each student needs to have a way to run python in a Jupyter notebook, as this is how the lab work will be turned in.

Note, this page discusses python in general. Also see the more specific instructions for using Jupyter Notebooks.

The Command Line

You will need a very rudimentary understanding of how to use the command line in this course. If you have never used the command line before, I would strongly encourage you to work through the Django Girls tutorial. There are a number of other tutorials available as well. I have also found this cheat sheet of useful commands helpful.

Python Tutorials

There are a large number of python tutorials available. If you have never used python before, I would recommend starting with the python.org tutorial. If you prefer videos, you can follow the Google python introduction. These both assume you have some familiarity with the concept of programming. If you are really starting from scratch, you might consider reading through some of the online books in the python.org Beginners Guide, or the Python for Everybody lesson videos.

Getting python

I have left this section here as a possible reference, but for PHYS 391 we will be requiring students to use python through a Jupyter notebook.

Each student needs to find an acceptable solution to allow them to work regularly with python. Python does run on Windows, Mac OS X, and Linux, and all user files are portable between the different versions, so you should be able to find one or several solutions which work for you.

There are two main versions of python (v2 and v3) which are not completely compatible with each other as discussed below, and we will be using some add-on packages to make our life easier. For this reason, I would strongly encourage anyone who isn't particularly computing savvy to run python in a Jupyter notebook from Anaconda. The use of Jupyter is described on the Jupyter page.

The following is a list of possibilities in rough order of ease for the student.

Running python

If you have successfully found a version of python which you can run, you should be able to work through the python.org tutorials, either from the command line or better within a Jupyter notebook.

Python 2 vs. Python 3

From a command-line, you can test your version of python with:

$ python --version

Note: $ is the shell prompt. You type everything after the shell prompt. If you get a version 2 result (I get 2.7.10 on my Mac), you might try the command python3 instead.

There are actually not that many differences between version 2 and 3, but a few are rather significant.

There are a number of other technical differences, but these are the main ones that will trip us up. More details are on the python.org site.

Even though I tend to use v2 in my own work, we will try to exclusively use v3 in this class. This version is now 10 years old, and as students you shouldn't be living in the past. If you have to use v2.7 for some reason, you can actually write scripts in v3 syntax by adding declarations like the following to the start of any python script:

		from __future__ import print_function, division
	

This tells python to use the v3 print and division syntax even if you are in v2.7. A full list of the available v3 changes that can be imported into v2.7 is described here. It is much easier to just use v3, however.

Python Resources