samantham

Update Cursor Code Add New Field

Discussion created by samantham on Jun 9, 2012
Latest reply on Jun 10, 2012 by nahmed-esristaff
In the code below I am attempting to add the new field "FullAdr" to the hospitals shape file. Then I run the update cursor to add new values to the "FullAdr" field, but the new field does not display the information I want. Instead it its blank. It should have the full address.

import arcpy
try:
    arcpy.env.workspace = "c:/Test/Shapefiles"
    arcpy.AddField_management("Hospitals", "FullAddr", "TEXT", "50")
    updCursor = arcpy.UpdateCursor("Hospitals")
    for row in updCursor:
        strAddress = row.ADDRESS
        strCity = row.CITY
        strState = row.STATE
        strZip = row.ZIPCODE
        strFullAddress = strAddress + "," + strCity + "," + strState + "," + strZip
        print strFullAddress
        row.SetValue("FullAddr", strFullAddress)
        updCursor.updateRow(row)
        #The above code block is supposed to create a create the new field
        #FullAddr, the field is created; however, it does not display
        #the full address: strAddress + strCity + strState...etc
        
    print "Update Complete"
    del updCursor
except:
    print arcpy.GetMessages()


here is the output, the new field "FullAdr" but it is blank it doesnt contain the new set value of "strFullAddress"

[ATTACH=CONFIG]15086[/ATTACH]

Attachments

Outcomes