Proper programming – python

However flashy programs can get with products such as Scratch and MIT App Inventor, they still don’t feel quite like proper programming.  This time I’m going to take a look at getting started with Python.

The first problem is which version to use: there are two versions of Python currently in use, Python 2 and Python 3.  Each has its own current version number. Some of the issues are seen in the argument in the comments on the book I’m using to get started, Hello World: computer programming for kids and other beginners.

python book

The book I’m starting with

The book does not come with a CD (although you can send off for one), but it provides a link to a website where you can download the entire package of programs and modules needed to complete the exercises in the book.  I started with Python 2.7 from the python website itself, but when I hit one or two problems I used the downloader for Python 2.5 from the book website, which turned out far simpler to set up than doing it all myself and includes all the modules and code you’ll need.  Later I’ll probably switch to python 3.2, which is the version of Python used by other resources I have, and so will probably have to sort out modules etc for myself, but to start with I’m going for the straightforward version of doing everything by the book, so to speak.

Python comes with its own IDLE (Integrated Development Environment) which is a shell.   This means that you can run commands directly and see the immediate result.  You can also open a new window, write and save your program and then run it.  Not far into the book, though, you are recommended to switch to the SPE, another way of writing and compiling programs, as this is said to work better with easygui, a module that helps with creating interactive buttons and boxes.  This is the point where I got stuck and resorted to the book download, as I couldn’t get the SPE set up and running (possibly just because I have python 2 and 3 installed and am feeling my way with installing the extra stuff in the right place).  So far I haven’t had any problems using the IDLE with easygui, however.

python numberguess printout

printout for the numberguess game

python numberguess code

The code for the number guess game

The first program, of course, is the standard hello world program.  This ability to print something onscreen is rapidly developed into asking for input and acting on it, and by the end of the first chapter I’d created a simple number guessing game, although not everything in the code had been explained by this point.

One thing I’m finding irritating when using the IDLE is that when I first write code it’s beautifully colour coded, which helps the design process, but once I’ve saved and run the code, it then reverts to black on white.

The book itself is simple to follow, although I’ve had issues where a listing goes over to the next page and the indentations aren’t always clear to follow on; indentation is very important in Python, as there are no semi-colon line endings or curly brackets to indicate blocks of code.

a box for entering the guess

A box for entering the guess

The easygui module makes it easy to create simple boxes to enter information, although the way that box disappears to be replaced by the next gives the programs a rather clumsy appearance.  Nevertheless, it proved straightforward to replace console version of the number guessing game with a version that displays messages and input boxes.  This does, however, have the disadvantage that previous guesses are no longer displayed on screen.

color coded python

color coded python code

The general impression I get from python is that it’s fairly straightforward to use, but still far tougher than the simplicity of programs like Scratch and App Inventor, as you have to know what commands you need to use and how to word them properly, as well as sorting out layout and typos.  It does, however, feel much more like real programming, and is of course a language that is used professionally.

Learning it will be much more a case of referring to notes and practice, rather than being able to jump straight in and experiment.  All in all, it’s an exact illustration of the difference between a graphical user interface and a command line interface, and reinforces why we’re all using Windows or similar operating systems rather than still typing DOS commands!


About emmyleigh
Writer/editor/proofreader who loves technology

2 Responses to Proper programming – python

  1. Jason Pitt says:

    Loved the post.

    Quick tip with regards to code in IDLE turning black and white: When you save the file be sure to add .py on the end of the file name. (i.e. This tells IDLE its a Python file and means it will apply the syntax highlighting

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: