Monday, May 2, 2011

Importing: The Basics

Everyday, when I look at the forums, there are always many posts asking for help because they are new at programming in python.  To start, you need to load the ArcGIS Python library into the python script.  To access the library, use the import function to access the 'arcpy' library.

Simple Examples:

import arcpy


Now you can begin using all the modules, libraries and classes contained within the ArcGIS Python Library.

Let's say we just need the Spatial Analyst libraries. Instead of loading the whole library, just load part of the arcpy library.


from arcpy import sa


The Geo-statistical analyst module

from arcpy import ga

The mapping module

from arcpy import mapping

This can be done for all the python modules, and it allows users to load just what they want.