Help With Selection Loop

Discussion created by rsaadgis on Dec 17, 2010
Latest reply on Dec 17, 2010 by lpugh01
I'm trying to loop through a polygon feature class and select each polygon, then select streets within that polygon, and then create a frequency table of street names from the street selection. I'm new to python so could someone offer some help as to what I'm doing wrong with the following code I'm using within the Python Window. It works but does not iterate to the next polygon selection. In other words the process runs on the first polygon selection and exports a frequency table but then stops instead of moving onto the next row in the search cursor. Here's my code:

>>> rows = arcpy.SearchCursor("Beats","","","SHORTBT")
...   for row in rows:
...        beat = row.SHORTBT
...        arcpy.SelectLayerByAttribute_management("Beats","NEW_SELECTION","\"SHORTBT\" = '" + beat + "'")
...        arcpy.SelectLayerByLocation_management("road","HAVE_THEIR_CENTER_IN","Beats")
...        arcpy.MakeFeatureLayer_management("road",beat + "_RoadLyr")
...        arcpy.Frequency_analysis(beat +"_RoadLyr",beat + "_RoadNames","FULL_NAME")
... del row, rows, beat