What I'm attempting to do is create a list of .dbf tables using a wildcard which I've managed to do. From there my goal is to search the list and extract the value of a specific field. This field only contains 1 row, the value will then be used to populate a field contained in another table which, I haven't begun to attempt yet.Below is a code snippet:

tableList05 = arcpy.ListTables("*_2005.dbf")
#for table05 in tableList05:
with arcpy.SearchCursor(tableList05, ['SUM'])as cursorFive:
    for row in cursorFive:
       print row

For now I'm simply trying to get those values to print before trying to manage how to copy them and update the records in an existing table. The error message I receive when I run this section of code tells me the .dbf tables don't exist.


`tableList05' - assuming it isn't empty - contains a list of the filenames only. No path names

You need to set the workspace so Python knows where these tables are located:

Option 1:

arcpy.env.workspace = "<folder>"

Option 2:

#The variable now contains absolute paths to the tables.
from os.path import join
tableList05 = [join("<folder>", tbl) for tbl in arcpy.ListTables("*_2005.dbf")]
  • Sorry, I forgot to mention, 10.1 and I did set the environment workspace, it is at the beginning of the code, I just didn't show it. I just tried re writing the code: tableList05 = arcpy.ListTables("*_2005.dbf") for table05 in tableList05: cursorFive = arcpy.SearchCursor(table05, ['SUM']) for row in cursorFive: print row Now I get the following text for the print statement: <geoprocessing row object object at 0x000000000DB90DB0> – standard Jul 16 '14 at 20:01
  • 2
    Need to use row.getValue("Sum"). I'd suggest you move to the data access module though as it's faster and you might find it easier to use. – Paul Jul 16 '14 at 20:04
  • Thanks @Paul, I think using your suggestions I may have come up with a more efficient way which doesn't require as much geoprocessing to complete the task as I couldn't get the .getValue statement to return the correct value. – standard Jul 16 '14 at 20: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.