For Microsoft Windows, download, from http://www.python.org/download/
Choose the Windows Binary MSI installer. These notes use V2.7, but there is also a V3.x, which has new features. Most tutotials use the older version, and this is a reason to use it.
Save the small MSI file anywhere, then run it. Accept all the defaults on the install.
You will find a link to Python on yourStart menu. On the sub-menu, there are a number of choices.
We we use the IDLE programming environment.
On Linux, it is likely to be there already. On Ubuntu, to get Idle, type:
sudo apt-get install idle
Then you can type idle at the command prompt.
Using IDLE
Run Idle - you will see a screen of the form:
Python 2.x.y (#37, Oct 14 2012, 17:02:34) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.8 -- press F1 for help
>>>
This is known as the Shell, and can be used to enter single Python instructions.
We will not use this feature often.
To create a program:
-
In the Shell window, use the File menu, selecting New Window. (Here, we shorten the
menu actions to File | New Window )
-
Type in your program. Here is a small one to try:
print "Hello"
print "World"
Note: use print, not PRINT or Print
-
Save it, by File | Save As from the new window (not the shell). Choose any name, but it
must end in .py For example, greeting.py
-
Now run it, by choosing Run | Run Module in the new window (NOT the shell window)
Switch to the Shell window to see the results, which in
this case are:
>>>
Hello
World
>>>
The added >>> (Chevrons) are not part of your results. They indicate where you can type stuff if need be.
-
To amend your program, switch back to the new window (which now shows the name of your
Python program in its title bar), make changes, and do a File | Save. If you don't save your
changes, a pop-up shows when you run the program, asking you if you wish to save it.
-
Ensure you save your program before quitting.
-
In your next session, create the new window, and use its File| Open. Select the file to open.
DO NOT use File|Open on the shell window.
| |