SciMeth 204 – Frequently Asked Questions

What is Python anyway?

Python is an interpreted, interactive, object-oriented programming language. It is often compared to Tcl, Perl, Scheme or Java. It is easy to learn and combines remarkable power with very clear syntax. The language has modules, classes, exceptions, very high level dynamic data types, and dynamic typing. A small number of powerful high-level data types are built into the language. Python can be extended in a systematic fashion by adding new modules implemented in a compiled language such as C or C++. Such extension modules can define new functions and variables as well as new object types. Python is also usable as an extension language for applications that need a programmable interface. In addition, there are existing interfaces to many system calls and libraries, as well as to various windowing systems (X11, Motif, Tk, Mac, MFC). Because of this simple yet flexible framework, Python is well suited to both uncomplicated everyday programming tasks as well as large and complex programming projects.

Python's development was started in 1990 by Guido van Rossum at the National Research Institute for Mathematics and Computer Science (CWI) in the Netherlands, and continues as an Open Source Initiative project. Python is available for virtually every type of computer in existence today, from personal PCs to mainframe supercomputers. Because of its widespread availability, and because it is easy to learn as someone's first programming language and yet powerful enough to accomplish large and complex tasks, the popularity of Python has grown rapidly. It is now taught extensively as a "first-time" programming language, and there is an EDU special interest group that serves the common needs of the Python-in-education community.

Often, programmers fall in love with Python because of the increased productivity it provides. Since there is no compilation step, the edit-test-debug cycle is incredibly fast. Debugging Python programs is easy: a bug or bad input will never cause a segmentation fault. Instead, when the interpreter discovers an error, it raises an exception. When the program doesn't catch the exception, the interpreter prints a stack trace. A source level debugger allows inspection of local and global variables, evaluation of arbitrary expressions, setting breakpoints, stepping through the code a line at a time, and so on. The debugger is written in Python itself, testifying to Python's introspective power. On the other hand, often the quickest way to debug a program is to add a few print statements to the source: the fast edit-test-debug cycle makes this simple approach very effective.

[Portions of the above text were excerpted from the www.python.org web site.]

Where do I get Python?

Python is available from www.python.org. New versions are released regularily. For the PC204 course, we'll be providing coding examples using Python 3, which is scheduled to officially replace Python 2 soon (see Python 2.7 Countdown). You can download for free a version of Python for your personal computer from here. If you have trouble installing Python on your computer, send e-mail to conrad@cgl.ucsf.edu and ask for help.

What's different about Python 3?

Python 3 is the first ever intentionally backwards incompatible Python release! Python 3 was released in early 2009 and has gradually been incorporated into various platforms and operating system releases. Even though there were more changes than in a typical Python release, and more that were important for all Python users, they nevertheless mostly involve fixing well-known annoyances and "warts" that had crept into the language since it's first release in the early 1990's. However, incompatible changes take time to adjust to, and to check and perhaps fix the literally thousands of existing Python modules that are available on the web, and it's taken from 2009 until now to accomplish this.

I'm using the Vim text editor when writing my programs, but none of the Python key words are shown in color. What's wrong?

Okay, so this question only gets asked ocassionally but it's still answered here. When Vim starts up it reads the contents of the file ".vimrc" in your home directory. That file contains configuration commands, among which are a couple which turn on syntax highlighting. And since indentation is used a lot in Python, another useful configuation setting is to have the keyboard "tab" key insert four spaces instead of the usual eight so that your programs are easier to read. These configuration commands and a few others are listed in this sample .vimrc file:
set autoindent magic sh=/bin/bash wrapscan exrc nobackup
set tabstop=4 shiftwidth=4 expandtab
set nomodeline	" ignore commands in files that alter vim's behavior
set nohlsearch	" don't highlight every match found during searches
syntax on	" enable syntax processing
let python_highlight_all = 1	" enable all python highlighting features
colorscheme zellner		" preferred color scheme
highlight pythonSpaceError term=reverse cterm=bold ctermfg=7 ctermbg=7	" more subdued hl color
set guioptions=agimrLt	" see http://vimdoc.sourceforge.net/htmldoc/options.html#%27guioptions%27
If you want to know more about vim and .vimrc files, here's the online documentation. And if you'd like to see some of the other color schemes that are available, just look here.

My question is not listed here!

Think we should have covered an important PC204 topic that we didn't? Just send e-mail to tef@cgl.ucsf.edu and let us know what we've forgotten. We'll be happy to add to this list.