GEOG 485:
GIS Programming and Software Development

1.4.4 Exploring Spyder


Here’s a brief explanation of the main parts of Spyder. Before you begin reading, be sure to have Spyder open so you can follow along.

When Spyder opens, you’ll see a large text editor in the left side of the window.  We'll come back to this part of the Spyder interface in a moment.  For now, focus on the pane in the lower right called the IPython console.  This console is much like the Python interactive window we saw earlier in the lesson. You can type a line of Python at the In [1]: prompt and it will immediately execute and print the result, if there is a printable result. This console can be a good place to practice with Python in this course, and whenever you see some Python code next to the In [1]: prompt in the lesson materials, this means you can type it in the console to follow along. 

We can experiment here by typing "import arcpy" to import arcpy or running a print statement.

In [1]: import arcpy

In [2]: print ("Hello World")
Hello world 

You might have noticed while typing in that second example a useful function of the IPython console - code completion. This is where Spyder, like Pro's Python window, is smart enough to recognize that you're entering a function name and it provides you with the information about the parameters that function takes. If you missed it the first time, enter print( in the IPython window and wait for a second (or less) and the print function's parameters will appear. This also works for arcpy functions (or those from any library that you import). Try it out with arcpy.Buffer_analysis.

Now let's return to the left side of the window, the Editor pane.  It will contain a blank script file by default (  I say it's a blank script file, because while there is text in the file, that text is delimited by special characters that cause it to be ignored when the script is executed.  We'll discuss these special characters further later, but for now it's sufficient to note that Spyder automatically inserts the character encoding of the file, the time it was created, and the login name of the user running Spyder.  You can add the actual Python statements that you'd like to be executed beneath these bits of documentation.  (You can also remove the documentation, if you like.)

Among the nice features of Spyder's editor (and other Python IDEs) is its color coding of different Python language constructs.  Spacing and indentation, which are important in Python, are also easy to keep track of in this interface.  Lastly, note that the Editor pane is a tabbed environment; additional script files can be loaded using File > New or File > Open.

Above the Editor pane, a number of toolbars are visible by default.  The File, Run, and Debug toolbars provide access to many commonly used operations through a set of buttons.  The File toolbar contains tools for loading, running, and saving scripts.  The Run toolbar contains a "play" button that can be used to test your script without having to double-click the file in Windows Explorer.  Finally, the Debug toolbar contains tools for carefully reviewing your code line-by-line to help you detect errors. 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.