Python track: lab 1


Getting set up on the CS cluster

DO NOT SKIP THIS SECTION!

Many of you will want to develop and run your programs on your own computer, and you are welcome to do so, but the official environment for developing your programs is on the CS cluster. This consists of (a) the computers in Annenberg 104 which run Linux, and (b) any remote login machines available for the cluster. [Currently, there are no remote login machines available on the cluster, but we're working on it.] They all run the same software. You need to do a few small things to get set up to use an up-to-date programming environment on the CS cluster.

The first rule is as follows:

Do not, under any circumstances, develop or run your programs on the CS cluster machine called login.cs.caltech.edu or login.cms.caltech.edu! This computer is not intended to be used for program development at all.

Instead, if you want to develop and test your code remotely, use a remote login machine, if there is one. It will work just like all the other CS cluster computers in the lab.

The software for the CS 11 Python track lives in the directory /cs/courses/cs11/install. In order to make this software available to you, you need to do these simple steps:

  1. Log in to a CS cluster computer.

  2. Execute the following line in a terminal (where % represents the terminal prompt):

    % cp /cs/courses/cs11/setup/bashrc-cs11 ~/.bashrc-cs11
    
  3. If you do not have a file in your home directory called .bashrc (use ls -a to check for files beginning with a dot, which are normally hidden), execute the following line in the terminal:

    % cp ~setup/general.bashrc ~/.bashrc
    
  4. At the end of your .bashrc file, add the following line:

    source ~/.bashrc-cs11
    

Now log out and log back in again. You're all set!


Getting started

Go through as much of this python tutorial as you can stand. If this tutorial is too fast-paced or too difficult, consult this page for a list of python tutorials at all levels. This tutorial is also pretty good.

Writing python scripts/programs

Here are some simple python scripts that you should write. Don't forget the magic line:

    #! /usr/bin/env python

in the first line of your file. Make your files executable by typing

    chmod +x <filename>

at the Unix prompt and test them. NOTE: scripts designated [Advanced] are optional but are worth extra credit if your total mark is less than perfect. Also note that in python-speak, the words "script" and "program" mean exactly the same thing. Also also, you won't have to make your scripts executable in this way for any labs other than this one; we cover this here because it's a common way to use python and you should know how it works. You're free to continue to make your later scripts executable if you like, of course. For this lab only, don't put the .py suffix on your program names; for all subsequent labs, do add the .py suffix.

Make sure that scripts that require command-line arguments check these arguments for validity (correct number of arguments and correct types), and output a usage message if the arguments are invalid. See the style guide for more details on how to do this (specifically, this section). This applies to ALL programs you hand in in this track; if you don't do this I'll make you rewrite the offending program(s).

While you're at it, run your completed programs through the style checker to check your code formatting style. If it complains about tabs, see this section of the style guide for advice on how to configure emacs to not output tabs. If you're not using emacs, you're on your own.

Programs to write

That's plenty for this week.