Python Programming in Context


Published by Jones and Bartlett Publishers

Textbook Resources for 3.x

A Note about cTurtle

If you are using idle, some of the initial interactive examples will appear to hang. This is due to some weird threading interactions between the IDLE GUI and the shell. The problems are frustrating when you run into them in the first chapter. However as you write programs longer than 4 or 5 lines that include the exitOnClick call, and start to use the editor they dissappear quickly. A couple of suggestions to avoid this initial frustration:

A Note about Python 3.x

(September 2009) Python 3.1.1 is now final. We suggest moving to this new version.

As of the time of this note (Sept 15, 2008) the book is out, but Python 3.0 is still in Beta. The links to cTurtle and cImage provided above work with the latest Python 3.0 beta. However, the Python developers are still working out bugs in 3.0 and idle. We went with Python 3.0 because our release dates were scheduled so close together and we heard from many colleagues that Python3.0 was important. As with any major software release there are bound to be some rocky patches.

The good news is that although Python 3.0 breaks backward compatibility with 2.x the differences for beginners are relatively minor. If you are uncomfortable with the state of 3.0 you can still use the book with Python 2.x with very little problem.

The main difference programmers are likely to encounter is that the print statement has become a function. Whereas in Python 2.x you write print "hello world", in Python 3.0 you write print("hello world"). The semi-good news is that in Python2.x you can still write print ("hello world") without getting a syntax error. However Python will literally print ("hello world") as a single item tuple.

Another difference that shows up early in the book is the range function. In Python 2.x range returns a list. In Python 3.0 range returns a range object. From a functional point of view the behavior is exactly the same. But from a visual point of view, when students are using idle for example, they appear different. Actually we prefer the 2.x behavior for teaching since the students can actually see the sequence of numbers produced by a call to range.

By the time you get to dictionaries you will notice that the dictionary methods items, keys, and values return dictionary proxy objects. In the book we wrap these calls with the list function to convert the proxy object to a visible list. This is not necessary in 2.x but it is also harmless. Using the functions in regular code does not require the call to list and so does not need any changes between 2.x and 3.0

Python 2.5/2.6 Resources

These modules will run with Python 2.5 or 2.6, the code in the book will work fine with these older version of the modules.