Select to view content in your preferred language

argument of type 'int' is not iterable when trying to copy rows

974
2
02-03-2022 12:50 PM
BillJacobs
Emerging Contributor

I am trying to use arcpy to loop through 20 or so feature classes, select by attribute certain rows and export to a new feature class. The field names are all different, so I want to identify if these words exist in ANY of the fields in the entire attribute table. Below is my script, but I keep getting hung up on:  TypeError: argument of type 'int' is not iterable.

Help!

import arcpy
import os
import sys
import arcpy
from arcpy import env 
from arcpy.sa import Con
from arcpy.sa import *
arcpy.env.overwriteOutput = True


inworkspace = r'F:\St Kateri Conservation Center\GIS\Ohio\Ohio_parcels_prj_2.gdb'
outworkspace_c = r'F:\St Kateri Conservation Center\GIS\Ohio\Ohio_C_Parcels.gdb'
outworkspace_results = r'F:\St Kateri Conservation Center\GIS\RESULTS\Ohio_Results.gdb'
#set the environment
arcpy.env.workspace = inworkspace

parcels = arcpy.ListFeatureClasses()
print(parcels)

for fc in parcels:
    infc = fc
    outname = "c_" + fc
    outfc = os.path.join(outworkspace_c, outname)    
    arcpy.CopyFeatures_management(infc, outfc)
    arcpy.DeleteFeatures_management(outfc)
    curT=arcpy.da.InsertCursor(outfc,"*")
    with arcpy.da.SearchCursor(infc,"*") as cursor:
        for row in cursor: 
            if any(['Cat' in substring for substring in row]):
                curT.insertRow(row)
            elif any(['St' in substring for substring in row]):
                curT.insertRow(row)
            elif any(['CAT' in substring for substring in row]):
                curT.insertRow(row)
            elif any(['Sisters' in substring for substring in row]):
                curT.insertRow(row)
            elif any(['Saint' in substring for substring in row]):
                curT.insertRow(row)
0 Kudos
2 Replies
DanPatterson
MVP Esteemed Contributor

you should limit your fields to string/text fields at least

ListFields—ArcGIS Pro | Documentation

before you try to search them


... sort of retired...
KimGarbade
Frequent Contributor

I agree with DanPatterson.  I think its bailing because your asking it to iterate through strings to find "CAT" and "St" and its saying "I can't do that because this is an integer". ListFields looks like it could be useful here.  The returned fields know their datatypes.  

https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/listfields.htm