Select to view content in your preferred language

Why does search cursor within a custom toolbox delete feature class

505
1
Jump to solution
09-21-2023 04:04 PM
ZacharyKasson
Occasional Contributor

I am trying to iterate through the attribute table to find duplicates of a field which is supposed to be a unique identifier. I figured I would use a tool to take in a parameter(feature class) as an argument for a search cursor, then append the result to a list. I was hoping to use that list to find duplicate values. 

I have ran into a weird instance where the feature class I use as a parameter is deleted upon clicking the 'Run' button. Of course I then get an error: 

 

  File "Y:\Zack\Duplicate_stand_finder.atbx#DuplicateID_Duplicateidfinder.py", line 20, in <module>
RuntimeError: cannot open 'Y:\Zack\Default.gdb\Rand_points'

 

 Here is the code that I tried for testing purposes.

 

ids= []
feature_class = arcpy.GetParameterAsText(0)
field = arcpy.GetParameterAsText(1)

with arcpy.da.SearchCursor(feature_class, field) as cursor:
    for i in cursor:
        ids.append(i[0])
arcpy.AddMessage(ids)

 

0 Kudos
1 Solution

Accepted Solutions
ZacharyKasson
Occasional Contributor

I figured it out. I must have accidentally set the parameter feature_class as an output instead of an input. 

View solution in original post

0 Kudos
1 Reply
ZacharyKasson
Occasional Contributor

I figured it out. I must have accidentally set the parameter feature_class as an output instead of an input. 

0 Kudos