2012 April 19,

CS 111: Technical Issues

Carleton College, Spring 2012

Prof. Joshua R. Davis, , Goodsell 106B, x4473

Summary of Terminal Commands

The files on a computer are organized into folders, which are also called directories. In addition to files that store documents and programs, a directory may also contain other directories, which contain other files and directories. Within a terminal program, you can navigate through this system of files and directories using a few simple commands.

Submitting Work Electronically

To submit your work electronically:

Warning: Once you have placed a file on the COURSES file server, you cannot edit it or remove it. So make sure that your files are exactly as you want, before you submit them.

Three Versions of Python

Python is constantly growing and evolving. Each new version of Python adds new features. Python 3 not only added new features, but also broke compatibility with earlier versions of Python. Right now, the worldwide Python community is in a transitional phase, where a lot of Python 2-based software has to be rewritten to work with Python 3. Unfortunately, this transition complicates your life a bit. You may run into three different versions of Python:

So what do you need to know and do? It's pretty simple, actually.

For a full list of changes between Python 2 and Python 3, see What's New in Python 3.0.

Python Programs Opening in IDLE

I recommend that you edit your programs in TextWrangler and run them in the terminal, as described in Intro to Python, Part B. If your Carleton lab computer account (or your personal computer) is set up "correctly", then double-clicking on any Python program file should open that file in TextWrangler.

For some students, Python program files instead open by default in IDLE, which is an integrated editor-and-runner for Python programs. If you have this problem, and you want to change your default to TextWrangler, then perform the following steps. (These instructions are for Mac OS X; a similar procedure surely exists for Windows.)

  1. In the Finder, locate any Python program file.
  2. Get Info on the file, by selecting the file and pressing Command-I.
  3. In the Get Info window, go to Open With, then Other..., then the CarletonApps folder; choose TextWrangler. You have just declared that you want this particular Python file to open in TextWrangler.
  4. In the Get Info window, press Change All.... You have just declared that you want all Python files to open in the same way.

White Space

When you type on a computer, you use various letters, digits, and symbols. You also use various white space characters, including spaces, tabs, returns, etc. Sometimes one kind of white space can look like another. For example, depending on how your text editor is set up, a tab may look just like four spaces. A line of text may end because of a return, or because of a space between words, if your text editor wraps subsequent words to the next line.

Even though a tab may look like four spaces, or a space may look like a return, the Python interpreter can tell the difference. And Python is rather unusual among programming languages, in that it cares about the difference. When you indent a block of Python code, all of the indentations must match exactly. If they don't, then you get an error. Such errors can be hard to correct, because you can't even see them. For example, here I am editing some Python code in TextWrangler. You don't have to understand the code here; just look at the indentation.

Everything looks good, but the code isn't working as I expect. Based on prior experience, I suspect that the indentations may be messed up. So in TextWrangler I go to the View menu, then Text Display, then select Show Invisibles. Here's what happens.

Special symbols are displayed for returns and tabs, while spaces are still invisible. We see that each line ends in a return. Lines 15-21 and 24-25 are indented using spaces. But lines 22-23 are indented using tabs. Python doesn't like that. I fix this by manually changing each tab to four spaces. I save and re-run the program, and it works. I can then turn off Show Invisibles (because it's irritating), or leave it on (for safety).