Removing/Replacing specific characters from a field

1388
10
Jump to solution
10-31-2018 03:54 PM
GIS_geek
New Contributor III

I am trying to remove specific characters from a field called CCTV_SLID.  The field I am working with looks like this CLMH123W456MH123W455, STMH123W457, SIMH123W458, SYMH123W459.  I am trying to remove the prefixes which are CL, ST, SI, and SY.  I have the following script and get a IOError: "C" does not exist error. Any help would be appreciated. Thanks.

# Remove prefix from CCTV_SLID


fcLst = "C:/Desktop/CCTV.gdb/GravityMain"
for fc in fcLst:
    fieldList = [f.name for f in arcpy.ListFields(fc) if f.type == "String"]
    if fieldList:
        with arcpy.da.UpdateCurson(fc, fieldList) as cursor:
            for row in cursor:
                for i in range(len(fieldList)):
                    row = row.replace("CL"," ")
                    cursor.updateRow(row)

0 Kudos
10 Replies
GIS_geek
New Contributor III

Thank you all for your help.  I really appreciate it.

0 Kudos