Python Notes - Installing

Contents   Installing Python   Variables   Input/Output   if   while   Functions - def   Scopes (local/global)   Function parameters   Lists (arrays)   Dictionaries   Tuples   Files   Libraries   Hints, tips  

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:

  1. In the Shell window, use the File menu, selecting New Window. (Here, we shorten the menu actions to File | New Window )
  2. Type in your program. Here is a small one to try:
    
    print "Hello"
    print "World"
    
    Note: use print, not PRINT or Print
  3. 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
  4. 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.
  5. 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.
  6. Ensure you save your program before quitting.
  7. 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.

Contents   Installing Python   Variables   Input/Output   if   while   Functions - def   Scopes (local/global)   Function parameters   Lists (arrays)   Dictionaries   Tuples   Files   Libraries   Hints, tips