AnsweredAssumed Answered

Slicing fields in arcpy.da.UpdateCursor

Question asked by AChapman@jmt.com_jmt on May 17, 2018
Latest reply on May 23, 2018 by jborgion

I am trying to join multiple fields using an update cursor, I want to trim a filed to a specific length while the cursor iterates through and adds another field to the final string. I am working with a streets data set and will need to do this for streets that have no pre direction and streets that have a pre direction. I want to take only the first 5 character of the street name when there is no pre directions and the first 3 character when there is a pre direction.  


When I run this script (testing it only for streets with no pre direction)  I do not get any errors but nothing is updated in the feature class.


    import arcpy

    fc = r'C:\Users\achapman\Documents\18_0157_Woodlands_TX\WOODLANDS_TX.gdb\WOODLANDS_CL_WGS84'
    pbid = ['PRE_DIR', 'ST_NAME', 'ST_TYPE', 'pBID']

    with arcpy.da.UpdateCursor(fc,pbid) as pbid_cursor:
        for row in pbid_cursor:
            if (row [0] is None):
                row[3] = (row[1][:5]) + row[2]