Scientific Python Basics

This lesson will be a crash course in programming. We're using the Python language, which is popular in science, but the principles we're teaching are applicable to programming in any language.

You're coming into this lesson with different amounts of programming knowledge. If you have done little or no programming before, you may find that the lesson proceeds very quickly. Don't hesitate to ask the volunteers around the room for help, or team up to work on exercises together. If you have done some programming before and you're comfortable with the lesson material, see if you can help others around you.

The files

The student notebook has spaces for you to type in the code yourself. We often remember things we write better than things we just see, so it's worth the effort to follow along with this. If you missed something, though, you can go back to it in the master notebook, which has the code filled in.

Starting an IPython Notebook

To learn about these core concepts and the Python language, we'll start off by working within the IPython notebook.

To start up a notebook, open Terminal and navigate to the folder containing the ipynb notebook files that you wish to open (or to any directory in which you'd like to save a new notebook, if you're creating a new notebook from scratch). Once in the directory, run the command ipython notebook, which will launch a local webserver and open your default browser. From there you can open an existing notebook, create a new notebook, and start working.

Note that if you are on a Windows machine, this command may not run under mysysgit or Cygwin. If it doesn't, open a Command Prompt (click on the Start menu and type cmd in the search box for Windows 7, or click on Run then type cmd for Windows XP), navigate to the appropriate directory, and run the command ipython notebook.

Going further

Extra lessons in this course will teach you about loading and saving data files, plotting graphs and unit testing. You can also ask the instructors and helpers about recommendations for specific things you want to find out how to do.

The course repository has a lot more lesson material that we're not presenting. The Python Scientific Lecture Notes site is a detailed introduction to using some of the major scientific Python tools. And there is plenty more information on the web about Python and scientific Python tools.

The Berkeley Python site gathers links to resources and news of relevant events happening on campus.