1

I want to print all feature class names along with field names from a GDB, which are having empty/blank records in text file for user. Fields in feature classes are not same. So I want to skip some particular fields which are not requited to check for empty records. Below is my code and I don't know how to skip some fileds

import arcpy  
from arcpy import env 

env.workspace =  r"C:\Users\Test\Basemap.gdb\ROAD"

fclist = arcpy.ListFeatureClasses()

# want to find empty records for below list of feature classes
fields = ["S_CODE","CATEGORY"]

f=open(r'C:\Users\test\List_GDB\Empty_rec.txt','w')
for fc in fclist:
    
    bad_list = []
  
    for field in fields:
        #print (fields)
        with arcpy.da.SearchCursor(fc, field) as cursor:
            for row in cursor:
                if row[0] in ["", None, " "]:
                    bad_list.append(field)
                    break
               
    f.writelines(fc+"contains empty records in"+str(bad_list)+"\n")

f.close()

enter image description here

Above is GDB structure. Please suggest how to skip particular fields (Ex: CODE, ADDRESS etc) in all feature classes while checking for empty records.

0

1 Answer 1

2

You could omit specific fields using an if statement within a list comprehension:

fields = [x.name for x in arcpy.ListFields(fc) if x.name not in ["CODE","ADDRESS"]]
2
  • In my others words, Each feature class in GDB, having some extra fields which are not required to check for empty records. So Intentionally I want skip some specific fields which will be specified at time of running code and also results to be written for text file.
    – Arb
    Sep 18, 2020 at 16:09
  • This is working
    – Arb
    Sep 18, 2020 at 16:39

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.