Getting Started

What will we cover?
  • How to start Python and what an error message looks like - just in case...
  • How to create a VBScript and JavaScript program.

IMPORTANT NOTE: Although I use 3 languages you are not expected to type in all of the exercises in all 3 languages. That would just be confusing. You might want to try all of them in the early examples just to get experience of using them. However, as you get beyond the first couple of topics you should choose one (I recommend Python, but you can choose one of the others if you prefer) and type those examples in, then simply read through the other language examples to note the similarities and differences between them. That way you should get a feel for both reading code (an important skill for a programmer in itself) and understanding the common ideas between all programming languages.

Using Python

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. (If you are a Windows user and don't know what a command prompt is or how to start one then read the sidebar sidebar below. I assume Linux users will be familiar with terminal windows, and MacOS users just have an icon to click as usual.) The Python prompt should appear looking something like this:

Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

Alternatively you might find a shortcut to something called IDLE, or the Python GUI, in your start menus. If you start IDLE instead of the command line version you will get a similar prompt but in a window of its own and with some pretty font colors! Danny Yoo has written a pretty good IDLE Tutorial to get you started with IDLE and I recommend you pay it a visit if you want to stick with it rather than the basic command prompt. It duplicates some of the early material here but repetition of the basics is no bad thing!

The full manual for IDLE is found here. For now I'd recommend you stick with Danny's tutor.

One interesting thing about IDLE is that it is itself a Python program, so it's a very good demonstration of just what is possible using Python

If you got your version of Python from ActiveState or if you downloaded the Windows specific extensions (the winall package), you also have access to another GUI programming environment, very similar to IDLE but perhaps a little more polished, called Pythonwin. Either Pythonwin or IDLE make far better programming environments than the standard DOS prompt, but at the very beginning I prefer to use the most basic tools to focus on the underlying principles rather than the toys.

The Windows Command Prompt

Since I first wrote this tutorial it has become obvious that many Windows users are no longer familiar with the venerable MS Dos command prompt. This sidebar will describe how this invaluable tool can be accessed and provide the bare minimum on how to use it.

There are several ways to access the command prompt. The simplest way is to go to the Start Menu and select Run.... In the dialog that appears type cmd and hit OK. A black window should appear with a white textual prompt saying something like:


This indicates the folder where the user is now located and typing DIR and hitting return should display a list of all the files in the directory. You can also try typing python and if all is well you should see the familiar >>> prompt and be able to type Python commands.

Unfortunately recent versions of Python have not apparently been setting things up such that the Dos prompt can find Python. If this is the case with you then you need to set an Environment Variable called Path.

Assuming you are using Win2000 or XP you do that by right clicking My Computer and selecting Properties. Go to Advanced and click Environment Variables.

You should find that 'Path' is already defined as a System variable so select it and click Edit. Be very careful in the next step not to delete the existing path by over-typing, if this does happen then press Escape or use the Cancel button to exit the dialog and start again.

In the Variable Value field go to the end and add a semicolon and the full path to your Python executable folder. OK your way back out. (If you don't know the full path to Python use Explorer Search tool to search for the file "python.exe" and the contents of the "In Folder" column of the search screen is the full path)

Now you can type python at the command prompt from any folder and it should start python. So you can CD (Change Directory) to the folder holding your script and type the command as per the tutorial. There is a list of DOS commands that you can type at the command prompt in the DOS help system. Just type help at the command prompt. For help on how to use any given command type the name of the command followed by /?. So for help on the DIR command that we used above, type:


Finally you can create a desktop shortcut by simply right-clicking the Desktop, selecting New->Shortcut. In the wizard that appears type cmd and click Next > then change the name to something like "Command Prompt" or similar. Click Finish and a new icon should appear on the desktop for you to click.

Take time to explore this powerful tool. It may seem primitive but it can be much more powerful, especially when doing repetitive tasks, than the GUI tools like Windows Explorer. A good place to start is the tutorial at c3scripts, there is also some information on the MicroSoft Developer Network(MSDN).web site.

A word about error messages

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 (most recent call last):
  File "<input>", line 1, in ?
TypeError: cannot concatenate 'str' and 'int' objects

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 <input> 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, usually the error is earlier in the line, or even in the (one or two) lines immediately preceding where Python says it is - 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 again that computers are dumb. Probably you just mistyped something or forgot a quote sign or something similar. Check carefully.

Basically there are three types of error you will encounter. The first of these is a syntax error which basically means that Python didn't recognise what you typed as a valid program, it's like missing out punctuation in an English sentence or spelling a word wrongly. The next category of errors is a runtime error which is where the program looks valid but for some reason cannot be executed, you have tried to perform an illegal, or unavailable operation. Trying to read a file that did not exist would be an example. The final type of error is a semantic error which is where the program appears to have worked in that there are no error messaages but it produces the wrong output. For example if you wrote a word counter program that reported that this file only contained 5 words, it would obviously be wrong, so the program has a semantic error. Most of the errors you will come across initially will be syntax errors or runtime errors, later, as you start to design your own programs, you will make semantic errors and need to fix them. This process is called debugging and the errors so found are called bugs for historic reasons - one of the first computer faults was due to a real insect-type bug getting stuck inside the machine!

In case you are wondering, the mistake I made was trying to add a number to a character string which is a semantic error but in this case is one which also generates a runtime error.. 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 topic on the Raw Materials to understand what types are all about....

Whichever approach you've decided to take, command prompt or IDLE (or Pythonwin) we are ready to start creating some very simple Python programs.


To create JavaScript programs in a browser we need to do a bit more work. We need to create an HTML file which we can load into a web browser. An HTML file is really just a plain text file which you can create in Notepad or any other text editor. The file will look like this:


<script type="text/javascript">

document.write('Hello World\n');



The bit between <script...> and </script> is our program. I won't be showing all the HTML tags every time in this tutorial so you need to copy that file each time as a template and then replace everything between the script tags with the code you want to try out.


VBScript is essentially the same as JavaScript with the single difference that you replace the name "javascript" in the type= bit with, surprisingly enough, "vbscript". Like this:


<script type="text/vbscript">

MsgBox "Hello World"



Once again the bit between the <script> tags is the program.

VBScript and JavaScript errors

In both VBScript and JavaScript you will get a dialog box pop up telling you the line number of an error. There will also be a fairly inscrutable error message. As with Python, treat the line number as a rough guide rather than an exact pointer. After finding and fixing the error you will need to reload (or refresh) the page in your web browser.

OK, Whichever language you choose you are ready to start.

Points to remember
  • Start python by typing python at a command prompt
  • Error messages are nothing to be scared of, read them carefully, they usually give a clue as to why you got them.
  • But it's only a clue... if in doubt check the lines immediately before the reported line.
Previous  Next  Contents

If you have any questions or feedback on this page send me mail at: