ScottB

what am I doing wrong?

Discussion created by ScottB on Oct 24, 2011
Latest reply on Oct 24, 2011 by ScottB
Good morning,

Could someone tell me what I am doing wrong here? I am creating a table, adding fields to it, then trying to populate it.  The first two parts work fine (table creation and adding fields), however, I can not get it to add any data.

import sys, string, os, arcgisscripting, arcpy
gp = arcgisscripting.create(10.0)
gp.OverWriteOutput = 1

address = '201 Poplar Ave'
city = 'Memphis'
state = 'TN'
zipcode = '38103'

print address + ', ' + city + ', ' + state, zipcode

# Local variables:
Test_gdb = "C:\\GISData\\Distance\\Test.gdb"
Dist_Geo = "C:\\GISData\\Distance\\Test.gdb\\Dist_Geo"

# Process: Create Table
arcpy.CreateTable_management(Test_gdb, "Dist_Geo", "", "")

# Process: Address_Field
arcpy.AddField_management(Dist_Geo, "address", "TEXT", "", "", "", "", "NON_NULLABLE", "REQUIRED", "")

# Process: City_Field
arcpy.AddField_management(Dist_Geo, "city", "TEXT", "", "", "", "", "NON_NULLABLE", "NON_REQUIRED", "")

# Process: State_Field
arcpy.AddField_management(Dist_Geo, "state", "TEXT", "", "", "", "", "NON_NULLABLE", "NON_REQUIRED", "")

# Process: Add Field
arcpy.AddField_management(Dist_Geo, "zipcode", "TEXT", "", "", "", "", "NON_NULLABLE", "NON_REQUIRED", "")

Add_field = 'address'
City_field = 'city'
state_field = 'state'
zip_field = 'zipcode'

try:
    cur = arcpy.InsertCursor(Dist_Geo)
    row = cur.newRow()
    row.SetValue(Add_field, address)
    row.SetValue(City_field, city)
    row.SetValue(state_field, state)
    row.SetValue(zip_field, zipcode)
    cur.insertRow(row)
except:
    print gp.getmessages(0)
    gp.addmessage(gp.getmessages(0))

del cur, row

Outcomes