Books
There is no official textbook. Here are some recommendations:- Mark Lutz (2010) Programming Python. O'Reilly.
Comprehensive Python textbook. Covers Python 3.x, many examples and use-cases. - David Beazley,Brian K. Jones (2005). Python Cookbook. O'Reilly.
"Recipe style" solutions for every-day applications and different use cases. Version 3 for Python 3.3. - Marty Alchim (2010). Pro Python . Apress.
Covers advanced topics and software engineering skills. Available in the CU libraries as ebook.
Online Resources
- Official Python Documentation for 2.7.2 and 3.2.
- Dive Into Python 3.
Comprehensive online tutorial on Python 3. Also available as hardcopy. - ActiveState popular Python recipes .
User-contributed "recipe style" solutions for every-day applications.
Using the Command Line
To successfully complete the Python course you need to become comfortable using your operating system's command line terminal. There are many tutorials on using the command line online.
- For Mac OS X
- For Linux (this one is for Ubuntu)
- For Windows
Installing Python
Make sure to download Python 3.4.1. The code we will write in this class won't run on Python 2.x interpreters!
Mac OS X and Linux will have Python pre-installed, but usually only version 2.7 (or older).
The easiest way to install Python is to use your operating system's package manager (if you use Linux or a package manager in OS X). Cygwin for windows contains a package manager as well.
If you do not use a package manager on Mac OS X or you use Windows, you can download Python from https://www.python.org/downloads.
Running Python
Running the Python Interpreter (Read Evaluate Print Loop)
Open your terminal (see section "Using the Command Line" above). Then type "python" to run the interpreter in interactive mode. If you have multiple versions of Python installed (e.g. both 3.4.x and 2.7), you sometimes need to specify the version number (e.g. "python3" or "python3.4".If you use Windows, the command is often "py". If this gives you the wrong interpreter version, try "py -3"
Running Python Programs
A Python program consists of one or more Python source files with the suffix .py. The class will cover the structure of Python programs (which can also be in different sub-directories) in more detail. .py files are simple text-files, encoded in ASCII or UTF-8. You will have to use a basic text editor to create and edit these files. Examples of text editors are (in order of difficulty and powerfulness) Notepad (Windows), Textedit (Mac), Jedit, SublimeText, Nano, Vim, Emacs. There are also some IDEs that support Python, but I recommend a basic text editor while you are still learning the ropes.
Open your terminal (see section "Using the Command Line" above). Change into the directory that contains the Python file you want to run (for instance source_file.py). Then run "python source_file.py" (or "py source_file.py" on Windows). If your program does not work, Python will tell you the type of the error and the line in the source file that contains the error. You can then change your code, save, and run the program again. It makes sense to keep the command line to run Python and the text editor open at the same time. The class will cover debugging techniques in more detail.