I have a question for a current assignment that requires me to write a script that will add a new field to a feature class and then use a cursor to populate the new field by concatenating five other fields (name, address, city, stateabb, zipCode). The new field is FullAdd and will be the full mailing address in one field from the information that is already in the table.
I need help with the update cursor part of my code.
How do I make it write the concatenation to the new field?
I've tried so many things after the 'with cursor' statement and for loop and have no idea where to go next!
import arcpy from arcpy import env env.workspace = r"C:\mygdb.gdb" env.overwriteOutput = True # Set up search cursor for hospitals FC # Make the hospitals FC a lyr arcpy.MakeFeatureLayer_management("Hospitals", "Hospitals_lyr") # Add the new field arcpy.AddField_management("Hospitals_lyr", "FullAdd", "TEXT") fields = ['NAME', 'ADDRESS', 'CITY', 'ST_ABREV', 'ZIP_CODE', "FullAdd"] cursor = arcpy.da.UpdateCursor("Hospitals_lyr", fields) try: with cursor as updateCursor: for row in updateCursor: name = row address = row city = row stateAbb = row zipCode = row FullAdd = row FullAdd = str(name + " " + address + " " + city + ", " \ stateAbb + " " + zipCode) updateCursor.updateRow(row) # Copy feature lyr back to disk arcpy.CopyFeatures_management("Hospitals_lyr", "Hospitals_2") print "done" except: print "Error"