I would like to get a script running much faster than it is now. The script completes on my machine in about 33 minutes. It generates a report that counts features with specific attributes in one field. What I think is generally the problem to be solved is that there are 7 features classes in 70+ datasets, with 4 possible entries in the field that I want counted separately.

Here is a very reduced and plain version of the code, it shows generally the structure of the nested cursor in some nested for loops. I wonder if it is possible to NOT have the cursor creation be this nested??

state_plane_list = [...]
feature_class_list = ['PRCL_POL_',...]
clause = ["RESEARCH_STATUS = 'NULL'",...]

for state_plane in state_plane_list:
     for feature_class in feature_class_list:
          for rstatus in clause:
               cursor = arcpy.da.SearchCursor(feature_class + state_plane, fields, str(rstatus))  
                       ***Counting code here - everything ends up in a dictionary and eventually gets written to a csv using DictWriter() ****

Basically, is there another...hopefully more efficient... way to do this?? I feel like creating 1600+ cursor objects may be way too dense a procedure.


At the moment you are searching your entire dataset for each combination. You would probably find it quicker to use a view of state_plane, from that create a view of feature_class_list, etc.

N.B. View might be the wrong terminology for this database - it's been a while since my DB centric work - look at creating a query that creates a subset to search.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.