3

I am trying to run a very simple script to test the usage of arcpy.SearchCursor and row.getValue.

I want to do a very simple exercise: I have a table with some fields, and I want to print the values of one of the fields (e.g. fldname) for every record.

The script is the below:

import arcpy
IN_Table = "C:/ZZtest/test.mdb/table"
Field1="fldname"
cursor=arcpy.SearchCursor(IN_Table)
for row in cursor:
    printf=row.getValue(Field1)
    print(printf)
del row, cursor

When I am running this I have the error below:

Traceback (most recent call last):
  File "C:\ZZtest\ScriptName.py", line 28, in <module>
    printf=str(row.getValue(Field1))
  File "C:\Program Files (x86)\ArcGIS\Engine10.2\arcpy\arcpy\arcobjects\arcobjects.py", line 1048, in getValue
    return convertArcObjectToPythonObject(self._arc_object.GetValue(*gp_fixargs(args)))
RuntimeError: ERROR 999999: Error executing function.

I tried to search for similar questions. But they all included more complicated scripts.

My ArcGIS version is 10.2.

The type of the "fldname" field is Integer.

Where is my mistake?

  • Welcome to GIS SE. As a new user please take the Tour. Please edit the question to specify the exact version of ArcGIS in use. Your first mistake was using an "old" SearchCursor at all. They have been replaced by Data Access cursors (arcpy.da.SearchCursor), which use a different row access protocol. Using personal geodatabase could also be mistake (they are not compatible with 64-bit arcpy). But the problem lies with the datatype of or data within the "fldname" column (which you will need to describe in the question text) – Vince Dec 20 '16 at 12:29
4

Welcome to the GIS SE. I have edited your script. Please note:

  1. I have updated the search cursor to include the new, faster "da" approach. Please read up on using cursors here

  2. The script below will print out the value of the fld_name for each row in the table.

  3. Please use the raw input format when trying to identify file locations.

    import arcpy
    in_table = r"c:/ZZtest/test.mdb/table"
    with arcpy.da.SearchCursor(in_table, ["fld_name"]) as scursor:
        for srow in scursor:
            print srow[0]
    del srow, scursor
    
  • Thank you for your suggestions. I used this script and also changed the .mdb to a .gdb and it worked. – Philp Dec 20 '16 at 13:40
  • no problem. Please mark the question as answered to close it. – MacroZED Dec 20 '16 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.