Masthead

Overview of Python in ArcGIS 10

1. Python is all there is!

ESRI has chosen Python as it's one and only programming language for the ArcGIS software packages. There is also no upgrade path from the previous languages (Command line, VBA, VB, and MapObjects). This means all your scripts will have to be rewritten to Python. The good new is that Python is supported throughout the ArcGIS products and is well documented (with a few problems).

Note: MapAlgebra still exists within the raster calculator and you can use either Python or VBScript in the field calculator.

There are four ways of writing Python scripts that we'll be talking about:

The Python window in ArcGIS is the easiest way to get started accessing functions within ArcGIS but it is really challenging to learn the Python language and write script longer than a few lines in this window. The Python GUI is better but the Wingware IDE is a full Integrated Development Environment. All of these approaches allow you to access ArcGIS functions.

Note: If you use Wingware or any other software that does not come with ArcGIS you may need to set the path to the correct Python executable. This will be in "c:\Python26\ArcGIS 10...\" and is the "python.exe" file.

Feature Python Window (IDLE) IDLE (Python GUI) PythonWin Wingware
Comes with ArcGIS Yes Yes No $49.00 for personal version
Integrated into ArcGIS Yes No No No
Code-Completion Help Yes ? ? Yes, after "import"
Command line window Yes Yes Yes Yes
Executes scripts from files No Yes Yes Yes
Debugging Mode No Yes? Yes? Yes
Breakpoints NA Yes? Yes? Yes
Displays Variables NA No? Sort of? Yes
Stack Traces NA No? No? Yes

There are also other options for writing Python code:

2. Recommended Approach

We recommend the following approach to creating Python scripts:

  1. Tryout the functions (mostly ArcToolbox tools) in the "Python Window" in ArcGIS. The help is readily available and you can run the functions right away but it is very limited for writing complete scripts.
  2. Build your scripts in the Wingware or Python IDLE (GUI). The Python IDLE allows you to create scripts but it lacks many of the features you'll probably want to write scripts (code completion, debugging tools, etc.). The Wingware IDE is inexpensive ($49 for personal or academic use) and is a complete programming environment.
  3. For scripts that are completed and that you'll want to use again and again, or to distribution to others, you can create ArcGIS toolbox tools containing the scripts. These tools look and execute just like the standard tools and can be turned into button in ArcGIS and can be used in ModelBuilder.

The other recommendation is that you start a document that contains the functions and "code snippets" that you use commonly. This can be a handy reference for you and can be used to save snippets and functions you might use in the field calculator.

3. Getting Help

There is a lot of help provided in ArcGIS for Python.

During each lesson we'll show you how to use these help resources to make learning Python in ArcGIS easier.

There are also a lot of resources available on the Internet for learning Python outside of ArcGIS. Unfortunately, at this time, there are no books or good web resources for using Python with ArcGIS outside of the ESRI resources. Python in ArcGIS is new so I expect we'll start seeing a broader base of information for Python in ArcGIS. Please let me know if you find good resources and I'll add them to the website.

4. Also...

ArcGIS installs it's own version of Python at "C:/Python26/ArcGIS10.0. This version is not compatible with some Python packages like "JPype".

 

© Copyright 2018 HSU - All rights reserved.