TransWikia.com

Feature class and field names contains blank records in text file

Geographic Information Systems Asked on July 11, 2021

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:UsersTestBasemap.gdbROAD"

fclist = arcpy.ListFeatureClasses()

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

f=open(r'C:UserstestList_GDBEmpty_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.

One Answer

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"]]

Correct answer by Aaron on July 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP