Posts RSS Comments RSSTwitter 18 Posts and 24 Comments till now
This wordpress theme is downloaded from wordpress themes website.

Pro Python – Book Review

A recent thread on the Python Northwest mailing list asked for opinions on Marty Alchin‘s book Pro Python.  I thought I’d reproduce the answer I gave and expand on it a little.

I’ve owned Marty Alchin’s first book, Pro Django, for some time and was very happy with that purchase.  Based on that, I decided to buy his Pro Python book last year.  Pro Python is targeted at readers who are proficient with basic Python but are looking to push their skills further.  Quite naturally there’s a large number of beginners’ Python books out there but a shortage of more advanced books so it was nice to see this published.

Marty Alchin starts his book with a refreshing approach.  Rather than regurgitating Python facts to the reader, he takes a step by step tour of The Zen of Python discussing how it’s philosophy can be practically applied to make your programming more Pythonic.  He then delves into traditional topics such as classes, objects and strings as well as development topics such as packaging and testing.

I like Marty Alchin’s style of writing and find it to be clear and concise.  Even if you’re reasonably knowledgeable about the advanced topics he covers such as metaclasses, descriptors, introspection and multiple inheritance, I think the book benefits from the fact that these topics are backed up with good examples of how they work, and just as importantly, how they might usefully be used in ways you might not have seen before.  In fact, Chapter 11 walks through the building of a real world Python library which can be found on PyPI (try pip install Sheets) using the principles outlined in the previous chapters.

The other aspect of the book I find very useful is the fact that it is based on Python 3, however all examples are annotated and compared with the “legacy” Python 2 equivalent where relevant.  I’ve gotten a lot more comfortable with Python 3 by reading this book and better understand the improvements in the language from Python 2 to Python 3.

This isn’t a book aimed at newcomers to Python, even if you have a lot of programming experience, as it expects a reasonable amount of basic Python proficiency.  It’s also a “thin” book in the sense that it gives each topic a light treatment rather than aiming to be a complete reference.  This may or may not suit your needs, however there’s plenty of reference material elsewhere both online (e.g. the official Python documentation) and in print.

By comparison, the other advanced Python book I’ve read (and reread!) is Python In a Nutshell by Alex Martelli.  It’s based on Python 2.5 and getting a bit out of date, but much of it is still very relevant for all Python 2.x versions.  (I think a Python 3 version might be in the works).  It’s a much heftier and more detailed book and acts as much a reference text as well as being a book you’d enjoy reading from cover to cover.

In summary, I’d recommend Pro Python to any intermediate level Python programmer who’d like to advance their Python skills with a clear and concise text.

N.B. I am in no way associated with Pro Python, Apress or Marty Alchin … except of course for owning the book!

Why should kids be interested in programming?

My 10 year old nephew, Bob, loves computer games. In fact, I think it would be fair to say that most self respecting 10 year olds love computer games and wonder what else a computer is for apart from computer games, Facebook, Bebo, and the occasional use of that legacy communications medium called email.

My nephew, Bob!

There was a brief period in the 1980′s as the home PC revolution was picking up speed when we thought we would all have to learn how to program a computer. Computers were taking over the workplace and without this skill we would all be unemployable. That brief period ended with the rise of the office suite and the advent of email. For many jobs we’re now expected to have familiarity with word processors, spreadsheets, email and web browsing. You only really have to know how to program if you’re a programmer, whether hobbyist or professional, but that goes without saying. One could argue that the evolution of our technological society where programming is mainly restricted to dedicated programmers is a natural division of labour. Why should a secretary or an advertiser or a salesperson need to program? Why would a 10 year old need to program?

Bob can often be found discussing the merits of the computer games he plays and how they might be altered or improved. For example, earlier this week he described how he’d like to play a game which was a first person shooter where the enemy stood still and only fired back several seconds after being discovered. The game description was accompanied with much hand waving and shooting noises. There were further descriptions of the types of guns that should be available and when they should be made available to the player.

Bob’s vision of a new computer game was born from a creative process. What Bob needs now is a medium of creative expression to bring that vision to life. In the same way a musical instrument can be used to create an infinite variety of music, or a word processor can be used to create an infinite variety of novels, it is through programming that you can create an infinite variety of games, and programming is the medium of creative expression.

Michael Sparks asked the question: If you were 7 again, what would you expect to find in a book on beginning programming? Apart from the usual conditionals and loops (I can hear the writer of the fictional Functional Programming for 7 Year Olds groaning) it would make sense to fulfil our junior members of society’s primal need to play, adapt and create games.

Armed with the knowledge that learning to program was the path to learning to create computer games, Bob was all too happy to sit down with me and walk through some basic Python programming. We started with a simple quiz game. The first decision was to whether to choose Python 2 or Python 3. I figured that extensive library support wasn’t necessary for writing a quiz so I plumped for Python 3.  With Python 3, you also get to avoid being asked sticky questions such as:

Why is it called raw_input() and not input()?

…  and …

Why does raw_input() have brackets and print doesn’t?

The quiz went down very well and we got to touch on several Python constructs. Here’s a cut down version of what we wrote together:

score = 0

fvcolour = input('What is my favourite colour? ')
if fvcolour == 'red' or fvcolour == 'blue':
    score = score + 1

sport = input('What is my favourite sport to watch? ')
if sport == 'football' or sport == 'Football':
    score = score + 1

print('You scored', score, 'out of 2')

Bob was very excited by this.  He was particularly excited about the fact that he could get the computer to ask any question and respond to any answer in any way he wanted it to.  After helping him install Python 3 on his own computer and showing him how to use IDLE, he sat about creating more intriguing and inventive quizzes.

I was conscious of the fact that I only see Bob once in a while so I set about looking for an online tutorial he could follow.  I was also conscious of the fact that he really wanted to write games, specifically first person shooters with advanced sound and graphics!  A few weeks ago I attended the informative and entertaining tutorial Introduction To Game Programming given by Richard Jones at Europython.  Richard pointed us to Invent With Python, an online (and dead tree) book “written to be understandable by kids as young as 10 to 12 years old” teaching them how to program games using PyGame.  And it has been updated to Python 3.  Perfect.  Bob is busy working his way through the book and I can’t wait to play Bob’s first person shooter!

How would you introduce your 10 year old nephew / niece / daughter / son to programming?

Python 2.7 Released

The production version Python 2.7 is now available. Several features from Python 3.1 have been backported including language features such as the syntax for set literals, dictionary and set comprehensions, and multiple context managers in a single with statement.

These are great features of Python 3 and I’m sure I’ll use them in my Python 2.7 code, but I can’t help wondering if they also reduce the motivation for developers to move to Python 3. Are there enough compelling Python 3-only features to help promote the “upsell”?