This is a follow-up question to a previous post. For some reason the following script in Arcpy does not want execute the command. Please see fields and script below. (All credit to Aaron for the script)
import arcpy, os
fc = 'Segments'
with arcpy.da.UpdateCursor(fc, ["Name", "Name_From", "Name_To", "OID@"]) as cursor:
for row in cursor:
if row[0] != None: # Make sure there are no None type data
# 1) Split strings by "&" and 2) remove leading/tailing white space
cleaned = [x.strip() for x in row[1].split("&")] # "Name_From" field
cleaned2 = [x.strip() for x in row[2].split("&")] # "Name_To" field
# Tackling the "Name_From" field
if row[0] in cleaned: # Make sure "Name" is in "Name_From" field
cleaned.remove(row[0]) # Remove "Name" from field
if len(cleaned) > 1:
new = ' & '.join(cleaned)
row[1] = new
elif len(cleaned) == 1:
row[1] = cleaned[0]
else:
print "There was a problem with OID %s" % row[3]
# Tackling the "Name_To" field
if row[0] in cleaned2: # Make sure "Name" is in "Name_To" field
cleaned2.remove(row[0]) # Remove "Name" from field
if len(cleaned2) > 1:
new2 = ' & '.join(cleaned2)
row[2] = new2
elif len(cleaned2) == 1:
row[2] = cleaned2[0]
else:
print "There was a problem with OID %s" % row[3]
cursor.updateRow(row)