GEOG 485:
GIS Programming and Automation

1.4.4 Exploring PythonWin


Here’s a brief explanation of the main parts of PythonWin. Before you begin reading, open PythonWin so you can follow along.

When PythonWin opens, you’ll see what’s known as the Interactive Window. You can type a line of Python at the >>> prompt and it will immediately execute and print the result, if there is a printable result. The Interactive Window can be a good place to practice with Python in this course, and whenever you see some Python code next to the >>> prompt in the lesson materials, this means you can type it in the Interactive Window to follow along. In these ways, the Interactive Window is very similar to the Python window in ArcGIS.

To actually write a new script, click File > New and choose Python Script. Notice a blank page opens that looks a whole lot like Notepad. However, the nice thing about this interface is that the code is color-coded and the default font, Courier, is one typically used by programmers. Spacing and indentation, which are important in Python, are also easy to keep track of in this interface.

The Standard toolbar PythonWin Standard toolbar contains tools for loading, running, and saving scripts. This toolbar is visible by default. Notice the Undo / Redo buttons PythonWin Undo/Redo buttons, which can be useful to you as a programmer if you start coding something and realize you’ve gone down the wrong path, or if you delete a line of code and want to get it back. Also notice the Run button PythonWin Run button, which looks like a little running person. This is a good way to test your scripts without having to double-click the file in Windows Explorer.

The Debugging toolbar PythonWin Debugging toolbar contains tools for carefully reviewing your code line-by-line to help you detect errors. This toolbar is visible by clicking View > Toolbars > Debugging. The Debugging toolbar is extremely valuable to you as a programmer and you’ll learn how to use it later in this course. This toolbar is one of the main reasons to use an Integrated Development Environment (IDE) instead of writing your code in a simple text editor like Notepad.