python

Overview

Python is one a a handful of "scripting" languages, meaning that you can use python to write fairly sophisticated code, but you are still working with a very high level language, and one that does not require the use of compiler directives and library linking the way many "true" programming languages do. Perl is a similar, and similarly popular, scripting language. Which one you use ultimately is a matter of personal preferences.

A note about python versions

Python comes in two "flavors". In 2008, the python developer made the decision to radically rework the language as they moved from version 2 to version 3. The changes were all very sensible and made python better, but they left all existing python scripts unusable without major updates; needless to say that many people did not want to update their scripts and continued to use the older version. As a result, even today there are two incompatible versions of python you must decide between. People tend to label these 2.X and 3.X.

What should you do? If you are starting out, and will write scripts mostly for yourself (and not use a lot of other people's scripts), version 3.X is probably for you. There is one caveat: python derives much of its strength from 3rd party "modules" you can import. The most important, and popular ones exist for both versions. If you need something more specific, you should check to see which version of python your module is written for. The same is true if you expect to start with, and maintain, an existing body of scripts. If you are "inheriting" a bunch of 2.X scripts, then you will want to continue to use 2.X. As you maintain and change scripts, you can try to make them cross-version compatible. Some of the resources listed below describe how that is done.

python and python modules

Python is a very capable programming language. However, the utility python has as a general scripting environment comes from the large number of functional modules you can take advantage of, anything from accessing operating system functions to writing a complete web server in python!

Python Documentation

The official python site (python.org) has the full reference documentation for both the 2.X and the 3.X versions.

Getting python

  • python 2.X ships with stock Mac OS X installs.

  • On Linux, the packet manager for your favorite linux distribution is the best way to install python (the "python" package is 2.X, and the python3 package installs 3.X)

  • The python.org site has downloadable installers for all operating systems, including windows.

Note that python is designed carefully enough to allow you to install both 2.X and 3.X on the same machine. You will need to be a bit careful when invoking your scripts to make sure they are handled by the intended version.

Learning python

Books:

On the Safari e-book site, and at your favorite book seller:

Learning Python, 5th Edition
By: Mark Lutz
Publisher: O'Reilly Media, Inc.
Pub. Date: June 26, 2013
Print ISBN-13: 978-1-4493-5573-9

This book covers both 2.X and 3.X and is designed for folks who want to learn python.

Web Tutorials: