azsurveyor72

New to python scripting, script isn't working

Discussion created by azsurveyor72 on Nov 29, 2011
Latest reply on Nov 29, 2011 by csny490
Hello,

I am trying to learn some python coding. I altered someone elses code to get what is below. For some reason this code always fails at the rows = arcpy.UpdateCursor(zoneArcSelect, "([ZONE_CODE_12] = 'A-1')"). I am using this script at the end of a modelbuilder, model. It seems to me that this should work! This is the error I get:
<type 'exceptions.RuntimeError'>: ERROR 999999: Error executing function.
An invalid SQL statement was used.
An invalid SQL statement was used. [zones_polygon_Union]
An invalid SQL statement was used. [SELECT * FROM zones_polygon_Union WHERE ( ([ZONE_CODE_12] = 'A-1') )]
Failed to execute (CriteriaSector).

I am trying to learn this and would appreciate if someone could help me out!

Thanks!


import arcpy, sys, os

# Get feature class from argument

zoneArcSelect = sys.argv[1]

# Add Criteria field to input feature class

arcpy.AddField_management( zoneArcSelect, "Criteria", "TEXT" )

# Add Sector field to input feature class

arcpy.AddField_management( zoneArcSelect, "Sector", "TEXT" )

#get rows using update cursor and conflict selection
  
rows = arcpy.UpdateCursor(zoneArcSelect, "([ZONE_CODE_12] = 'A-1')")

# calculate value for Sector and update row

for row in rows:
   row.Sector = "Agriculture"
   rows.updateRow(row)

#get rows using update cursor and zone selection

rows = arcpy.UpdateCursor(zoneArcSelect, "([ZONE_CODE_12] = 'RPC') OR ([ZONE_CODE_12] = 'RM-1') OR ([ZONE_CODE_12] = 'R-T')")

# calculate value for Sector and update row

for row in rows:
   row.Sector = "Residential"
   rows.updateRow(row)

#get rows using update cursor and zone selection
  
rows = arcpy.UpdateCursor(zoneArcSelect, "([ZONE_CODE_12] = 'B-1') OR ([ZONE_CODE_12] = 'O-L')")

# calculate value for Sector and update row

for row in rows:
   row.Sector = "Commercial"
   rows.updateRow(row)

#get rows using update cursor and zone selection

rows = arcpy.UpdateCursor(zoneArcSelect, "([ZONE_CODE_12] = 'M-1') OR ([ZONE_CODE_12] = 'M-2')")

# calculate value for Sector and update row

for row in rows:
   row.Sector = "Industrial"
   rows.updateRow(row)

#get rows using update cursor and zone selection

rows = arcpy.UpdateCursor(zoneArcSelect, "([FID_zones_polygon_Clip] = '-1') AND ([Natural] = '0')")

# calculate value for Sector and update row

for row in rows:
   row.Criteria = "Leeton Area"
   rows.updateRow(row)
#get rows using update cursor and zone selection

rows = arcpy.UpdateCursor(zoneArcSelect, "([FID_zones_polygon_Clip] > '0') AND ([Natural] = '0')")

# calculate value for Sector and update row

for row in rows:
   row.Criteria = "Conflict"
   rows.updateRow(row)

#get rows using update cursor and zone selection

rows = arcpy.UpdateCursor(zoneArcSelect, "([FID_zones_polygon_Clip] = '-1') AND ([Natural] = '1')")

# calculate value for Sector and update row

for row in rows:
   row.Criteria = "Natural"
   rows.updateRow(row)

#get rows using update cursor and zone selection

rows = arcpy.UpdateCursor(zoneArcSelect, "([FID_zones_polygon_Clip] > '1') AND ([Natural] = '1')")

# calculate value for Sector and update row

for row in rows:
   row.Criteria = "Both"
   rows.updateRow(row)

Outcomes