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.]
Python is available from www.python.org. New versions are released regularily. For the PC204 course, we'll rely on language features found in release 2.7 or later (but not Python 3). 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 firstname.lastname@example.org and ask for help.
Python 3 is the first ever intentionally backwards incompatible Python release! Python 3 was released in early 2009 and is gradually being 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. Because of this, we'll still be using Python 2.7 in this course (actually any of the Python 2.x series should do), although we'll point out differences between Python 2 and Python 3 whenever we can. There's also a web page that described the differences.
If you want to try using Python 3 for your homework exercises and final project, by all means do so. Just let the instructors know your code is Python 3 compatible so that when we try it we'll know which version of Python to use.
If you don't have a personal computer onto which can install your own version of Python, you have two options. You can either use one of the Macs in the Library's Interactive Learning Center (ILC), or you can get an account on a Linux computer system that the Resource for Biocomputing, Visualization, and Informatics (RBVI) maintains for this purpose.
If you prefer to develop your Python programs on Linux, the RBVI has a Linux system known as "plato.cgl.ucsf.edu" for this purpose. Send e-mail to email@example.com to request that a plato account be created for you (in lieu of a PC account). Note that since plato is a Linux system, so you'll need to know your way around Linux in order to accomplish useful work. Instruction in Linux fundamentals is beyond the scope of this course, but there are a wealth of on-line tutorials available; just Google "unix tutorial". We also list some books about Unix/Linux in auxiliary reference materials.
You can access host plato is via the UCSF campus network, using either a PC or Macintosh computer in your lab, or by using one of the personal computers located in the campus library. You'll need to use an application that supports the "secure shell (SSH)" communications protocol. For additional information on SSH, including links to free versions that anyone can download via the Internet, see this SSH tutorial.
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: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.set autoindent magic sh=/bin/bash wrapscan exrc nobackup set tabstop=4 shiftwidth=4 noexpandtab 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
Think we should have covered an important PC204 topic that we didn't? Just send e-mail to firstname.lastname@example.org and let us know what we've forgotten. We'll be happy to add to this list.