Use udpateCorsor to instert characters in front of field values string

841
2
Jump to solution
08-08-2016 12:01 PM
CCWeedcontrol
Regular Contributor

I need help with some code. I need to add a back slash in front and end of values in a fields.

I can do it in arcpy.CalculateField_management like this arcpy.CalculateField_management(Merge_Layer, "Location", "''.join(('\'CITY!,'\'))", "PYTHON_9.3", "")

But i am not sure who to do it with arcpy.da.UpdateCursor, any help would be great.

I have this but it's not working.

with arcpy.da.UpdateCursor(fc, "CITY") as cursor:
            for row in cursor:
                    row[0] = row[0].format(str(!CITY!),"/")
                    cursor.updateRow(row)
0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor
with arcpy.da.UpdateCursor(fc, "CITY") as cursor: 
    for row in cursor: 
        row[0] = "".join(("\\", row[0], "\\"))
        cursor.updateRow(row)

View solution in original post

2 Replies
JoshuaBixby
MVP Esteemed Contributor
with arcpy.da.UpdateCursor(fc, "CITY") as cursor: 
    for row in cursor: 
        row[0] = "".join(("\\", row[0], "\\"))
        cursor.updateRow(row)
CCWeedcontrol
Regular Contributor

my second attempted was

row[0] =  ''.join(('\'row[0],'\'))

but now I see thanks,

0 Kudos