Saturday, 8 June 2013

Running a script using the command line

This simple example shows how to run scripts from the command line (aka console).  Pythonwin was the IDE.

import sys
import arcpy

try:
  featureClass = sys.argv[1]
  populationField = sys.argv[2]
except:
  featureClass = "c:/temp/x_pnts.shp"
  populationField = "FID"

rows = arcpy.SearchCursor(featureClass)
for row in rows:
  print  row.getValue(populationField)


  In this example a filename and field name were provided as parameter inputs.  If none where provided the try..except block would try to provide one.  Note:  no error checking to see whether the file or field exists.  You would have to bullet proof for these potential errors.

No comments:

Post a Comment