Select to view content in your preferred language

Function to delete records

8671
11
05-19-2016 10:45 AM
LianaSmith
Frequent Contributor

I need a small code in python that will delete records that have empty value in a specific field of the layer. The name of the feature class is WCSCustomer and the name of the field is GROUTE

0 Kudos
11 Replies
curtvprice
MVP Alum

I found code to strip all non printables on StackOverflow.

def stripper(s):
    return "".join(i for i in s if ord(i)<127 and ord(i)>32)

fc = r"C:\tmp\Test.gdb\WCSCustomer" 
field = "GROUTE" 
with arcpy.da.UpdateCursor(fc, field) as rows: 
    for row in rows: 
        try: 
            val = stripper(s)
        except: 
            val = row[0] 
        if val in ["", None]: 
            rows.deleteRow(row) 
DanPatterson_Retired
MVP Emeritus

with the unicode encoding cavaet is people move closer to python 3.  Make sure you read that full thread, it is interesting... a "space" is much like "nothing"..it comes in many forms