Last
updated: Saturday 21st March 2015, 13:50 PT, AD
ConTEXT for Python
Introduction
Once
you've mastered how to create and run a simple Python program using Notepad,
you're now ready to learn how to use a more sophisticated editor such as
ConTEXT. ConTEXT was designed for use with a number of programming languages
including Python. ConTEXT has a number of features to help you develop your
Python programs including powerful syntax highlighting.
The
following screen shots show the same Python program with (ConTEXT) and without
(Notepad) syntax highlighting. Notice that with syntax highlighting, Python
keywords, comments, literal text etc are displayed in different colours or
fonts, which makes it much easier for programmers to find errors in their
program code. Not only can you edit Python programs using ConTEXT, but you can
also execute (run) them from within ConTEXT.
This web
page explains how to download, install and run the text editor ConTEXT for
editing and running Python programs.
How to Install and Run ConTEXT
1. Go to the ConTEXT web
site
In the
address box of your Internet browser, type in the following:
2. Download and Install the ConTEXT software
At the
time of writing this document the current version of the ConTEXT editor
software is version 0.97.5.You should always download the latest version of the
software as it will contain the latest features and bug fixes.
Click on
the 'Download' link on ConTEXT's home page, which is located at the top of the
page. You should then see the following screen:
Click on
the first DOWNLOAD link…
Click on
the Open button.
Click on
the Next > button.
Click on
the Next > button.
Click on
the Next > button.
Click on
the Next > button.
Click on
the Next > button.
Click on
the Install button.
When
installation is complete, the ConTEXT software will automatically execute, and
you will see the following screen:
You may
access the ReadMe.txt and History.txt files at any time, but for now, close
these files by clicking twice on the lower close button (marked with a
x) in the top right hand corner of the screen.
Your
ConTEXT screen will now look like this:
3. Setting up ConTEXT for Python programs
For
ConTEXT to be able to locate the Python interpreter and automatically invoke it
on your programs, you have to enter the correct settings. This only needs to be
done once. Proceed as follows:
Click on
the Options menu and select Environment Options:
From the Environment Options window, click on the Execute
Keys tab:
To add a
user execute key (a key set up to execute your Python programs), click on the Add button:
In the Extension edit window, type in py then press the OK button.
You will
now see the following screen. Click on F9 to see this screen:
Enter the
text for the Execute: and Parameters: text boxes:
Then click
on the Apply button, then the OK button.
ConTEXT is
now set up to edit and run your Python programs.
The
procedure outlined above set up the keyboard key labeled F9 to execute files with the
extension py (i.e.
Python programs) using the Python interpreter in interactive mode (requiring
Ctrl-Z to quit), using the saved the file name and path.
4. Creating a new Python program in ConTEXT
Select New from the File menu:
You will
then be presented with a blank editor window:
Type in
your Python statements:
Save your
file as a Python program file:
Select a
folder to save your new file from the Save in: text box, and make sure you select Python files for the file type
from the list of types available from clicking the down arrow button on the
right of the Save
as type: text box.
To run the
program, simply press the key on your keyboard labeled F9, or click on the user
execute key 1 (the first of the four buttons which has a picture of a human
head on it).
Press
Ctrl-Z to exit Python and get back to the ConTEXT editor.
5. Opening and running an existing program file
Select Open from the File menu:
Select the
file to open:
After
selecting the file and clicking the Open button, the file is displayed in the
editor window:
To run the
program, simply press the key on your keyboard labeled F9, or click on the user
execute key 1 (the first of the four buttons which has a picture of a human
head on it).
Press
Ctrl-Z to exit Python and get back to the ConTEXT editor.
6. Setting up ConTEXT for Python Help
When
Python is installed, a compiled HTML help file named Python23.chm is placed in
folder C:\Python23\Doc.
This file
can be accessed directly by clicking on the Start button in the lower left hand
corner of the desktop:
Start
-> Programs -> Python2.3.4 -> Python manuals
or
In
Explorer, double click on: C:\Python23\Doc\Python23.chm
You can
also set up ConTEXT so that this help system file will be executed when key F1
is pressed when you are editing a Python program within the ConTEXT
environment:
Proceed as
follows:
From the
Options menu, select Environment Options then click on the Miscellaneous tab:
In the
Help files box (see above) click on Python, then click on the Edit button.
From the
Open window (see below) click on the drop down arrow button on the right of the
'Files of type:' text box and select
'HTML help files (*.chm)'.
Locate
Python23.chm in the C:\Python23\Doc folder using the drop down arrow button to
the right of the 'Look in:' text box:
Click on
Python23.chm to transfer it to the File name: text box, then click on the Open
button:
You will
be returned to the following screen showing the connection between Python file
type and its Help file:
Important: You must click on the Apply button to save these changes.