Select to view content in your preferred language

my code fails with "geoprocessing object not iterable" in 9.3 but works in 10

517
2
Jump to solution
06-21-2012 11:10 PM
kyleturner
Deactivated User
Can anyone explain why my code fails with "geoprocessing object not iterable" in 9.3 but works in 10. Are there some compatibility issues going on? I wrote the python code in 10 but made sure not to make any calls to arcpy.
I invoked, gp = arcgisscripting.create(9.3)

My understanding is before 9.3, python didn't use 'real' lists, so calling list methods would obviously fail. Is that wrong? Is 9.3 not able to use list methods?

The following code, I believe, is where the problem is...I think??
# function to return appropriate 3.0 feature class for given 2.6 feature class # and it returns the name of the fieldname, FC_26_name def which30(two6ftrcls):      two6FC = two6ftrcls     whereclause = "Two6FCs = '" + two6FC + "'"     gp.AddMessage("whereclause is " +whereclause)     crosswalk = ShellPath + "/Two630FC_IDPKxwalk.dbf"     # The variables row and rows are initially set to None, so that they     #  can be deleted in the finally block regardless of where (or if)     #  script fails.     row, rows = None, None     Three0ftrlst = []     FC_26namelst = []     rows = gp.SearchCursor(crosswalk,whereclause)     row = rows.next()     if (row == None):         gp.AddMessage("check the Two630FC_IDPKxwalk.dbf table for Two6FCs -->" +two6FC)     elif (row != None):        rows = gp.SearchCursor(crosswalk,whereclause)        for row in rows:            if not row.isNull("Three0FCs"):               Three0ftr=row.getValue("Three0FCs")               Three0ftrlst.append(str(Three0ftr))               FC_26name = row.getValue("FC_26")               FC_26namelst.append(str(FC_26name))      if row: del row     if rows: del rows      return Three0ftrlst, FC_26namelst
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
markdenil
Frequent Contributor
The difference is in the 9.3 and 10 cursor objects.
The difference manifests itself in the application version, not in the geoprocessor version
(that is, a 9.3 geoprocessor cursor created in 10 uses the 10 behavior,
while the same code (with a 9.3 geoprocessor cursor) that will run in 10 will not run in 9.3)
(...and vice-versa)

In 10, one iterates the cursor:
for theRow in theCursor:     pass

in 9, one steps the cursor manually because the cursor cannot be iterated:
theRow = theCursor.next() while theRow:     pass     theRow = theCursor.next()


Even in 10, one manually steps an InsertCursor (for obvious reasons)

This is a real pain when having to write code that works in both versions
(don't ask, but I hope to be clear of 9.3 soon)

Actually, I rather liked the 9.3 behavior. One could easily run multiple simultaneous cursors in parallel.
Yes, there are other ways to do it, but I liked having the option.

View solution in original post

0 Kudos
2 Replies
markdenil
Frequent Contributor
The difference is in the 9.3 and 10 cursor objects.
The difference manifests itself in the application version, not in the geoprocessor version
(that is, a 9.3 geoprocessor cursor created in 10 uses the 10 behavior,
while the same code (with a 9.3 geoprocessor cursor) that will run in 10 will not run in 9.3)
(...and vice-versa)

In 10, one iterates the cursor:
for theRow in theCursor:     pass

in 9, one steps the cursor manually because the cursor cannot be iterated:
theRow = theCursor.next() while theRow:     pass     theRow = theCursor.next()


Even in 10, one manually steps an InsertCursor (for obvious reasons)

This is a real pain when having to write code that works in both versions
(don't ask, but I hope to be clear of 9.3 soon)

Actually, I rather liked the 9.3 behavior. One could easily run multiple simultaneous cursors in parallel.
Yes, there are other ways to do it, but I liked having the option.
0 Kudos
kyleturner
Deactivated User
Mark,

Wow...I'm glad I got someone with your knowledge to respond.
So, how do I write it to be used in both versions.

Incidentally, the only reason my code calls rows.next() is because early on in the development I was checking if rows was == None, which it never is because it always returns an object. So, I had to advance to a row to see if the row was == None.
Do you follow? (Also, have you figured out that I barely know what I'm doing....probably.)

Again, any help is greatly appreciated.
Feel free to email me at: turnerkyle@hotmail.com
0 Kudos