Frequently Asked Questions

Getting Help

How do I get help in this course?

There are many resources. Do not hesitate to come get help—the sooner the better. It frustrates us when we miss an opportunity to pull students out of confusion.

By the way, we follow Maxwell's rule of computer science. If you have been stuck on a problem and have made no headway in half an hour, ask for help! We know this material can be challenging, and we want you to work at it, but we do not want you to become frustrated.

When is the Roberts 225 computer lab open?

The lab is open until at least midnight each night. The Computer Lab schedule has information on when lab assistants are available to help, and also when classes are scheduled to meet in the lab.

Note that there may be space to work quietly at a computer while another class is meeting, but priority for machines is given to students in the scheduled class.

Network

What is a file server?

A file server is a network-attached file system that you can access from any computer. It enables you to save files in a centralized location so they can be accessed from another computer. It is like having a virtual USB key you can plug into a computer to store your files.

Colby maintains a personal file server, called filer, that you should use to save copies of your CS151 projects (and anything from other classes, too).

Why should I save my work to a file server?

Here are just a few reasons:

How do I access the file servers from the lab computers?

Open a Finder window. Select Go -> Connect To Server... from the menu bar (or press Command-k). This will bring up a dialog box titled "Connect to Server". Depending on which file server you want to connect to, enter the following network path, where you replace username and u with your personal login name and first letter.

ServerPath
filer smb://filer/personal/students/u/username
fileserver1 smb://fileserver1/Academics/COMP/CS151/username

Note: fileserver1 has been used in the past to submit assignments, but this semester we will use Moodle instead.

How do I access the file servers from my own computer?

Note: some students have reported problems connecting to network drives on the old "Colby Guest Access" wireless network. Be sure you are using the new "Colby Access" network, which uses a secure connection.

On Mac OS X, follow the instructions above. You may need to add .colby.edu to the server name:
smb://filer.colby.edu/personal/students/u/username

Mac OS X may not let you connect to two network drives with the same name (i.e. your username). If this is the case, connect to the Academics server using the connect string up to CS151, Then navigate to your directory in Finder after you connect.

On Windows, open Explorer (sometimes called My Computer, not Internet Explorer). Right click on the Computer icon and select Map Network Drive... (there may also be a Map Network Drive button in the Explorer toolbar); this will bring up a dialog box titled "Map Network Drive". For the Drive field, select an unused drive letter (like "Z:"). For the Folder field, use the path specified below depending on which server you want to connect to. (Note that the slashes go the other way.)

ServerPath
filer \\filer.colby.edu\personal\students\u\username
fileserver1 \\fileserver1.colby.edu\Academics\COMP\CS151\username

You will probably need "Connect using a different user name". In the "Connect As..." dialog, enter COLBY\username for your user name and use your Colby password. Then click OK and then Finish in the Map Network Drive dialog.

How do I access files on a file server from the terminal?

On Mac OS, all of the drives (including local hard drives, USB drives, and network drives) are visible in the /Volumes directory. For example, to navigate a CS151 directory you created on filer, type:

$ cd /Volumes/username/CS151

On Windows, use the drive letter that you specified in the Map Network Drive dialog.

> cd z:\CS151

Project Files

How should I organize the Python files I write in CS151?

We strongly suggest the following strategy. Create a directory named CS151 in your user's directory on the filer server (see the Network section).

When you start each project, create a new directory within CS151 to store all the files you work on for that project (e.g. project01). If the project builds on what you did in a previous project, copy the files from the previous project into the new project directory. This way, you keep a complete working version of each project as you finish it.

What do I need to turn in?

There are two components to every programming project: program code and a write up.

Program code is submitted via Moodle. You need to hand in everything required to run your program as an archive/zip. The strategy outlined above makes this easy. To archive a project (e.g. project01):

  1. Navigate to your CS151 directory in Finder.
  2. Right click on the project01 directory.
  3. Select "Compress project01" from the menu. This will create a file named project01.zip.
  4. Go to the CS151 website.
  5. Click on the link for the project assignment.
  6. Click on the "Browse..." button at the bottom of the page.
  7. Select the zip file you created in step 3.
  8. Click the "Upload this file" button.

The written component is to be completed on Colby's Wiki . Create a new page for each project, give the page an appropriate name (e.g. Project 1: Computational Thinking), and give the page the properly formatted project label, e.g. cs151s12project1. Note that the page title and label are two different things. The title can be anything descriptive. The label needs to match the label specified in the project description so we can find your page for grading!

Should I work with files stored locally on my computer or stored on the network?

You can do either. But do not mix the two because it will be very hard to determine which version of a program you are trying to run.

The advantage of working with files locally is that directories are easier to find (using Finder or the terminal), and any network interruptions will not affect your work (this happens rarely). But, when you work locally, remember to copy your work to a file server before you log out. The lab machines periodically have all user data removed! Also, there is no guarantee you can use the same machine the next time you visit the lab.

The advantage of working with files on the network is that the most recent version of your work is always available from any computer. (It is still recommended to keep at least one other copy of your work for a backup.) The disadvantage is that navigating the directories on a network file server is a little more complicated.

Terminal/Unix

What are the major terminal commands I should know?

These commands are common across all Unix systems, including Mac OS and Linux. There are similar, though not identical, commands for Windows.

pwd
Displays the present working directory.
ls
List the contents of a directory. For more information, use ls -lah.
cd <directory>
Change directory. If you use the command with no arguments, it changes the directory back to your top-level home directory, /Users/username/. The current directory is specified as . and the parent directory of the current working directory is specified using ..
mkdir <directory>
Create a new directory.
cp <from> <to>
Copy a file to a new location or name.
mv <from> <to>
Move a file, including just renaming it in the current directory. The mv command will remove the file in the old location after copying it to the new location.
rm <filename>
Remove a file (will not remove a directory).
cat <filename>
Print the contents of a file.
less <filename>
Scroll through a file (useful for long files).
echo "a string"
Write the text within the quotes to the terminal output.
touch <filename>
Updates the modification date on a file; creates an empty file if the file does not exist. This can be useful in various situations, like when you are learning to create, rename, and delete files using a terminal.
history
Displays a history of recently used commands.

Coding

I've made changes to my code, but when I run my program nothing is different! What's going on?

There are three common causes for this situation.

  1. You did not save the source file. Be sure to save the file (Command-s in TextWrangler) after you make changes.
  2. The file you edited is not in the directory where you are running Python. This happens a lot when students keep files for one project in multiple places. (See the suggested project directory strategy above.) Be sure that the location of the file you are editing matches the current working directory (pwd) of the terminal session you are using.
  3. The modification you made actually has no effect on the program. It is possible the code you are modifying never gets run; insert a print statement to see if this is the case. Common causes for this are calls to raw_input(), interspersing top-level code with function definitions, and unintentional top-level code in imported files (when you start using multiple files in a single project).

How do I use print statements for debugging?

Inserting print statements in your code is a great way to track down problems in your code. You can print out the value of any variable to see if it has a value you would expect. You can also add unique print statements in key locations of your code to see if a block of code gets executed. For example:

def drawMountains(x, y, scale):
    print "drawMountains() at (", x, y, ") with scale", scale
    
    ...

It is helpful to provide more information rather than less. It only takes a little more programming, and it is much easier to debug than a long chain of output that only says got here a bunch of times.

How do I comment my code appropriately?

See the comments section of the Grading page.

Images

How do I save an image of a window in Mac OS X?

Press Command-Shift-4 then press the space bar. This will bring up a camera icon. Select a window to save an image of the window to the desktop. The images are saved in PNG format with the name Picture 1, Picture 2, etc. You can rename them and move them as needed.

How do I create an animated gif?

First capture all of the pictures you want to store in your animation sequence. Put all the image files in one directory; it helps to give all files the same naming convention (windows captured from a Mac as above will).

Use the convert program in the terminal to create the animation as follows:

$ convert Picture*.png animation.gif

There is one catch. The order in which the files will be listed using Picture*.png is alphabetical. If you have more than 9 files, Picture 2.png will come after Picture 10.png, which is probably not what you want. The easiest way to fix this is to change the filenames of the first nine images (e.g. to Picture 01.png, Picture 02.png). Then the command above will get the pictures in the proper order.

The convert program is installed on all the Macs in Roberts 225. You can also download the program from ImageMagick to use it on your own machine (Windows, Linux, or Mac). Installing on a Mac requires compiling (see Software section).

TextWranger

How do I know where the file I am editing is located on the computer?

The file path is visible on the top toolbar of the TextWrangler window.

How do I display line numbers?

Select View -> Text Display -> Show Line Numbers from the menu.

How do I change the indentation on a block of code?

Select the block of code; press Command-[ or Command-] to move the block one tab stop to the left or right.

How do I switch between using spaces and tabs for indentation? Why does this matter?

In Python, formatting matters. Specifically, blocks of code are indicated by indentation level, and all lines that belong to the same block need to have the exact same indentation. Mixing some lines indented with tabs and others indented with spaces does not work.

Select Text -> Entab to ensure a file uses only tabs for indentation or Text -> Detab to use only spaces. We suggest you use tabs instead of spaces.

How do I get TextWrangler to launch from the terminal?

You can make TextWrangler the default application for editing Python (.py) files. Locate a Python source file in Finder. Right click on the file and select "Get Info" from the menu. On the Info pane under "Open with:", select TextWrangler (you may first need to select "Other..." and then find TextWrangler in the Applications folder). Press the "Change All..." button to associate all Python files with TextWrangler. Now, when you double click on a .py file, it will open in TextWrangler.

Moreover, you can now use the open command on the terminal to edit a Python file with TextWrangler. For example, to create and start editing a new Python file:

$ touch example.py
$ open example.py

Software

How do I install Python on my own machine?

If you want to use your own machine for programming, that is fine, but it will be easiest if you set up your machine to use the same version of Python that we run in the lab.

Note that not having software installed on your personal machine is not an excuse for failing to complete an assignment. The Roberts 225 lab is open until at least midnight every night, and all the machines in the lab have all of the software and libraries we use in this course.

For Windows, download installers for Python version 2.7.2, which is what we use in the lab. During lab 4 we will start using the Python Imaging Library (PIL), which is a separate download and install. Binaries are available for Windows. If you have problems installing PIL, remember you can always use the lab machines for completing these projects.

For Mac OS X, the version of Python we use is from MacPorts, which requires Xcode Tools. Xcode is on the OS X install disk that came with your computer. Once MacPorts is installed, the following will install Python, PIL, and ImageMagick. This will take a very long time.

$ sudo port install python27 py27-pil ImageMagick

What text editor should I use on my own machine?

There are so many available; see the list in the first Lab Exercise for some suggestions. For example, simple text editors that provide syntax highlighting include: jEdit and TextWrangler for Mac; jEdit and Notepad++ for Windows. (Note that jEdit requires a version of Java installed on the machine. Macs already have this; for Windows, this is a separate download and install from Oracle.)

Wiki

How do I use the Colby Wiki?

See this tutorial.

How do I embed code in a Wiki page?

You may include short code snippets in your write up if the code illustrates a point you are making in the text of the write up. Do this sparingly. You should not post large amounts of code on the Wiki!

The best way to do this is in Wiki Markup editing mode. The following example even provides syntax highlighting.

{code:python}
def randomFile(ext):    
    # find all files that match the extension
    files = glob.glob("*." + ext)
{code}

This yields:
wiki code