Programming with Python

The best way to learn how to program is to do something useful, so this introduction to Python is built around a common scientific task: data analysis.

Our real goal isn't to teach you Python, but to teach you the basic concepts that all programming depends on. We use Python in our lessons because:

  1. we have to use something for examples;
  2. it's free, well-documented, and runs almost everywhere;
  3. it has a large (and growing) user base among scientists; and
  4. experience shows that it's easier for novices to pick up than most other languages.

But the two most important things are to use whatever language your colleagues are using, so that you can share you work with them easily, and to use that language well.

iPython Notebook

We will be using iPython notebook for these lessons.

To open iPython notebook, open a new terminal (gitbash for windows) invoke:


$ ipython notebook


  • This will open a new page/tab in your web browser
  • Leave your terminal window open while using iPython
To open first lesson in your browser, click the "click here" link in iPython Notebook

Navigate to the lesson: Note: We assume you installed the course material in your home directory (~/ ), otherwise, navigate to the location of your 2015-03-06-nyas folder.

Analyzing Patient Data

~/2015-03-06-nyas/lessons/python/01-numpy.ipynb

Creating Functions

~/2015-03-06-nyas/lessons/python/02-func.ipynb

Analyzing Multiple Data Sets

~/2015-03-06-nyas/lessons/python/03-loop.ipynb

Making Choices

~/2015-03-06-nyas/lessons/python/04-cond.ipynb

Defensive Programming

~/2015-03-06-nyas/lessons/python/05-defensive.ipynb

Command-Line Programs

~/2015-03-06-nyas/lessons/python/06-cmdline.ipynb