Select to view content in your preferred language

import arcgisscripting and import win32com.client

3731
2
04-29-2012 01:09 AM
ElaineKuo
Regular Contributor
Hello,

I am a beginner to Python.
I would like to ask what the difference is between "import arcgisscripting" and " import win32com.client".
Also, please kindly advise any related references.

Thanks.
Tags (2)
0 Kudos
2 Replies
DanPatterson_Retired
MVP Emeritus
import arcpy     arcmap 10 and above
import arcgisscripting  arcmap 9.3 but can be used in 10
import win32com.client     older versions of arcmap
0 Kudos
curtvprice
MVP Alum
Dan is right but I think I'll add more detail for the record, since I have never seen all of this information in one place:

ArcGIS 9.0, 9.1 - PythonWin/GpDispatch
PythonWin's win32com module was used to access the geoprocessor through a "GpDispatch" COM object. PythonWin was a required install for ArcGIS.

import win32com
gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1") 
gp.workspace = "C:/work"
gp.Clip_management(...)


ArcGIS 9.2, 9.3 - arcgisscripting
A "native" Python geoprocessing module (arcgisscripting) was introduced. This was faster and more robust, and had the benefit of also being OS-independent, so ArcGIS Server applications on Unix could use Python. PythonWin became an optional install because it was not needed anymore. However, many folks still install PythonWin because of its nice IDE, which is much better than the the default (platform-independent) IDLE. PythonWin also offers many nice Windows-specific interfaces that Windows-centric developers can use.
import arcgisscripting
gp = arcgisscripting.create(9.3) # specify version for forward compatibility
gp.workspace = "C:/work"
gp.Clip_management(...)

The 9.2, 9.3 and 10.0 versions of arcgisscripting are slightly different. The differences I have run into are a) how cursors work, and b) the format of results from geoprocessor "list" methods (like gp.ListFeatureClasses).

ArcGIS 10.0 - ArcPy
The ArcPy site package was introduced at 10.0. Most of it is built on top of the arcgisscripting module; it offers lots of advantages for the script developer over the 9.x "gp" way of doing things, largely because it is more Pythonesque, especially in the way toolboxes and tools are accessed. The way ArcPy is set up allows IDE's to use intellisense (options pop up while typing code in an IDE). ArcPy also supports improved access to Spatial Analyst tools through "Python Map Algebra."
import arcpy
arcpy.env.workspace = "C:/work"
arcpy.management.Clip(...)
# Python map algebra
from arcpy.sa import *
maskRaster = Con(Raster("grid1") > 0, 1)



You asked for some reference material. I believe these two articles cover it:

ArcGIS 9.3 help: Creating the geoprocessor object
http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Creating_the_geoprocessor_object

ArcGIS 10 Help: What is ArcPy?
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v000000v7000000

If you're using ArcGIS 10 and don't have a need to write scripts that support earlier versions, arcpy is definitely the way to do it.
0 Kudos