Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

As I move through my small collection of python scripts written for arcgis 9.3 I'm discovering that many things work with little or no changes in arcgis 10. For example this pattern "just works":

import arcgisscripting
gp = arcgisscripting.create(9.3)
gp.workspace = 'd:/scratch'

even though the new way is:

import arcpy
from arcpy import env
env.workspace = 'd:/scratch'

So my question is, what it is the best structure to follow so that scripts are only written in the v10 way when they need functionality not available in earlier versions? Or perhaps better phrased as, what is the best structure for backwards compatiblity? I don't want to make my stuff automatically unavailable to people on earlier versions, just when it wouldn't work anyway.

share|improve this question
up vote 3 down vote accepted

You could try and account for different versions using ImportError exceptions. You could end up with a lot of If Else statements though.

ws = 'd:/scratch'
  import arcpy
  from arcpy import env
  env.workspace = ws 
except ImportError: 
  import arcgisscripting
  #or set a 9.x boolan flag here
  gp = arcgisscripting.create(9.3)
  gp.workspace = ws 
share|improve this answer
or maybe even from arcpy import env as gp ... (shudders) – Mike T Mar 16 '11 at 11:27
I was thinking the same thing... ; / – DavidF Mar 16 '11 at 16:24
yeahhhh shudders here as well. I was going to mention that... but i didn't. gp tools will work ok, other things such as cursors can be "for looped" with arcpy, NOT with arcgisscripting. There are other differences like this elsewhere. Dealing with them would be ugly and painful. – gotchula Mar 16 '11 at 22:19
@gotchula shudders at using importerror to check for the version or shudders to renaming the env class as gp? I was only suggesting the former - which is how nearly every other Python library deals with backwards compatibility. – geographika Mar 17 '11 at 7:11

we try pretty hard NOT to break when we ship a new release. When you install 10, the goal is that all your 9.x scripts would still work.

arcpy scripts will not work with a 9.x release. If you need to share your scripts with 9.x users you cannot use arcpy, you are correct. You can keep writing scripts using arcgisscripting, and the online help for arcgis desktop 9.x is here and contains the arcgisscripting api doc:

BUT if sharing with 9.x users is not a concern, we recommend going with arcpy, it is based on arcgisscripting but has great usability improvements over it (see search cursor difference for example) and it has a bunch more functionality (arcpy.mapping).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.