Searchcursor: How to add table from gdb to arcpy script?

181 views Asked by At

I have a gdb with a table that was generated from the Frequency tool and I want to add the table to the script. How can I access the table using a Search Cursor?

This is the script:

print "START"
print""

arcpy.env.overwriteOutput = 1

fc = "D:\AVI \zl\zevel.gdb\point"

list_Fields = arcpy.ListFields(fc)
my_list = ("a","b","c")

for name in list_Fields:
    if name.name in my_list:
        print name.name
        output = r"D:\AVI \zl\zevel.gdb"
        tbl_name = output + r"\tbl"+"_"+ name.name
        print tbl_name

       arcpy.Frequency_analysis(fc,tbl_name,name.name)

      ### arcpy.SearchCursor....
1

There are 1 answers

0
tpdance On

I usually call cursor's using a with statement so I don't accidentally forget to close them and cause a data lock.

with arcpy.da.SearcCursor(fc, list_fields) as sr_cursor:
    for row in sr_cursor:
        # some code

Alternatively:

sr_cursor = arcpy.da.SearchCursor(fc, list_fields)
for row in sr_cursor:
    # some code
del sr_cursor # don't forget to delete the cursor if using this method

Hope this helps. For more info, check the arcgis resources page: http://resources.arcgis.com/en/help/main/10.1/index.html#//002z0000001q000000