|What will we cover?|
|How to start Python and what an error message looks like - just in case...|
For the next set of exercises I will assume you have a properly installed version of Python on your computer. If not, go fetch the latest version from the Python web site and follow the install instructions for your platform.
Now from a command prompt type python and the Python prompt should appear looking something like this:
Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>>
If you type in the commands as we go through them then sooner or later you will get an error message. It will look something like this:
>>> print 'fred' + 7 Traceback (innermost last): File "
", line 1, in ? TypeError: illegal argument type for built-in operation
Don't worry about the exact meaning here just look at the structure.
The '>>> print ...' line is the erroneous command
The next 2 lines are describing where the error occurred
- 'line 1 in ?' means line 1 in the command we are typing. If it were a longer program stored in a source file the question mark would be replaced by the file name.
The 'TypeError...' line tells you what the interpreter thinks is wrong and sometimes there will be a caret character(^) pointing to the part of the line that Python thinks is at fault.
Unfortunately this will often be wrong - remember computers are dumb!
Use the error information to figure out what's happening. Remember it's most likely to be you at fault not the computer. Remember too that computers are dumb. Probably you just mistyped something or forgot a quote sign or something similar. Check carefully.
In case you are wondering, the mistake I made was trying to add
a number to a character string. You're not allowed to do that so
Python objected and told me there was a TypeError.
You'll need to wait till we get to the bit about 'Data'
to understand what types are all about....
Since I first wrote this tutor things have moved on a wee bit. There is now a nice Windows tool that ships with Python called IDLE. I discuss it a bit more later but you might find it easier to use than the DOS box described above. Even better, is that Danny Yoo has produced a nice introductory tutor to IDLE which you can visit here It only takes a few minutes to go through but it does explain it nicely with lots of screen shots. If you are using Linux IDLE isn't so useful because your shell window has many of the extra features that IDLE provides, you can defer using IDLE till later if you like. One interesting thing about IDLE is that it is itself a Python program, it's a very good demonstration of just what is possible using Python
Whichever approach you take, DOS or IDLE we are ready to start creating some very simple Python programs.
|Points to remember|
If you have any questions or feedback on this page send me mail at: email@example.com