iteration over non-sequence

959
4
04-08-2012 08:40 PM
AdelItani
New Contributor II
Please help me to correct this error:
....
....
....
# List all FOLDERS in master workspace
workspaces = gp.ListWorkspaces(dataFolders, "Folder")

# Iterate through the workspaces one at a time
for workspace in workspaces:  
#  Error:iteration over non-sequence
...
...
...
Tags (2)
0 Kudos
4 Replies
MathewCoyle
Frequent Contributor
You never mentioned what version of ArcGIS/Python you are using.

You need to set a workspace first.

You set a folder path (I presume) in the wildcard parameter.

See the help for info on how to use correct syntax.
http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=ListWorkspaces_method
0 Kudos
AdelItani
New Contributor II
Thanks Mathew,
I am using ArcGIS 9.2/Python 2.4 IDLE, CPython Windows XP.
import arcgisscripting
gp = arcgisscripting.create()
gp.OverWriteOutput = 'True'
...
...
gp.workspace = startFromFolder  # d:\projects\New\DaTa
workspaces = gp.ListWorkspaces(dataFolders, "Folder")  ## part_01

"""
    When using a 9.2-version geoprocessor,
    ListWorkspaces returns an enumeration instead of a Python List.
    """"

for workspace in workspaces:
...
...

What's the difference between enumeration and Python List ?
0 Kudos
MathewCoyle
Frequent Contributor
Enumerations from what I understand are an obsolete (in python) method of accessing data. Back when enumerations were popular I hadn't even heard of python yet, so I'm afraid I won't be much use.
0 Kudos
BruceNielsen
Occasional Contributor III
Processing the enumeration from gp.workspaces looks something like this:
import arcgisscripting
gp = arcgisscripting.create()
gp.OverWriteOutput = 'True'
...
...
gp.workspace = startFromFolder  # d:\projects\New\DaTa
workspaces = gp.ListWorkspaces(dataFolders, "Folder")  ## part_01
ws = workspaces.next() #get the first item in the enumeration
while ws: #repeat as long as ws has a value
    ...
    ...
    ws = workspaces.next() #usually the last line in the while loop
0 Kudos