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.


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 
  • 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
  • 1
    @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: http://resources.arcgis.com/content/web-based-help

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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