Conditional Statement to make Scripts Compatible with arcpy and arcgisscripting

2171
4
Jump to solution
02-22-2012 07:37 AM
Jasonvan_Warmerdam
New Contributor
Hello,
We are running two versions of ArcGIS at our office, 10.1 and 9.3. I am working on updating some of our python scripts and instead of making two different scripts for both, I wanted to see if I could just combine the two and have the geoprocessor catch a particular version with a conditional if statement. I know I could set a boolean sys.argv to prompt the user to enter their version of ArcGIS, but wanted to see if there was a phrase native to either arcpy or arcgisscripting that would trip the inital if statement if the user was running Arc 10 and if not the script would catch in the else statement for Arc 9.3.  

if [ArcGIS 10]:      Do this else [ArcGIS 9.3]:      Do this


Thanks,
Jason
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ChrisSnyder
Regular Contributor III
To be more explicit, you could use the .GetInstallInfo method. Something like:

try:    installInfoDict = arcpy.GetInstallInfo("DESKTOP") except:    installInfoDict = gp.getinstallinfo("DESKTOP")  if installInfoDict['Version'] == '10.0':    do this elif if installInfoDict['Version'] == '9.3':    do that else:    do someting completely different

View solution in original post

0 Kudos
4 Replies
DanPatterson_Retired
MVP Emeritus
Jason, did you try a simple try except block
try:
  import arcpy as gp
  gp_version = 10.0
except:
  import arcgisscripting as gp
  gp_version = 9.3


then you can do
if gp_version == 10.0:
  #do the arcpy stuff
else:
  #do the arcgiscripting stuff
0 Kudos
Jasonvan_Warmerdam
New Contributor
Thanks Dan!
That try statement worked great.
Jason
0 Kudos
ChrisSnyder
Regular Contributor III
To be more explicit, you could use the .GetInstallInfo method. Something like:

try:    installInfoDict = arcpy.GetInstallInfo("DESKTOP") except:    installInfoDict = gp.getinstallinfo("DESKTOP")  if installInfoDict['Version'] == '10.0':    do this elif if installInfoDict['Version'] == '9.3':    do that else:    do someting completely different
0 Kudos
JasonScheirer
Occasional Contributor III
Just write your scripts for 9.3. They'll be backwards compatible in 10.0.
0 Kudos