1

I am trying to write a script that will loop through a table, and based on the values that are contained in the field of a table of a feature class in a geodatabase, it will print the name of the field that contains values that meet a certain crireria. Here is what I have so far:

fields = [field.name for field in fieldlist]
cursor = arcpy.da.SearchCursor(fc, fields)
 for row in cursor:
    for col in row:
       if isinstance(col, ( int, long ) ):
          pass
       elif type(col) == unicode:
           Strcol = unicodedata.normalize('NFKD', col).encode('ascii','ignore')
           if int(len(Strcol)) < 10 and Strcol.isdigit():
                if Strcol.startswith("55") or Strcol.startswith("56") or Strcol.startswith("57"):
                    print Strcol
                    print field.name

What this script does for me currently is it print out all of the values in all of my tables that match the criteria, but, with the field.name print statement, it automatically defaults to the last field in my field list. Is there a way to print the name of a field automatically when it finds values of the field that meet a desired criteria. (eg a field that contains values that are unicode strings, less than 10 characters, that are digits, which start with 55, 56, or 57)

3
for counter, col in enumerate(row):
...
    print fields[counter]

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.