[GIS] TypeError: ‘NoneType’ object is not iterable from Python Scripting for Geoprocessing Workflow exercise

arcgis-10.1arcpypython

I am currently taking ESRI's Python Scripting for Geoprocessing Workflows. I have following their step by step however there seem to be a problem that I am getting an error.

import arcpy
#Set geoprocessing environments
arcpy.env.workspace = "C:/Student/PythonGP10_0/Data/SanJuan.gdb)"

arcpy.env.overwriteOutput = True

#Create list of feature classes in SanJuan.gdb
fclList = arcpy.ListFeatureClasses()

#Create a loop to buffer Lakes and Streams
bufferList = []
for fc in fcList:
    if fc == "Lakes" or fc == "Streams":
        arcpy.Buffer_analysis(fc, fc + "Buffer", "1000 meters")
        bufferList.append(fc + "Buffer")
arcpy.Union_analysis(bufferList, "WaterBuffers")

The error I get here from the IDE Window shows the error:

PythonWin 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32.
Portions Copyright 1994-2008 Mark Hammond - see 'Help/About PythonWin' for further copyright information.
>>> import arcpy
Traceback (most recent call last):
  File "C:\Python27\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\Student\PythonGP10_0\Scripts\BufferWater.py", line 9, in <module>
    for fc in fcList:
TypeError: 'NoneType' object is not iterable

Best Answer

You have a ) at the end of your workspace path. And then you have fclList, but you use fcList in the for loop.

import arcpy

#Set geoprocessing environments
arcpy.env.workspace = "C:/Student/PythonGP10_0/Data/SanJuan.gdb"

arcpy.env.overwriteOutput = True

#Create list of feature classes in SanJuan.gdb
fcList = arcpy.ListFeatureClasses()

#Create a loop to buffer Lakes and Streams
bufferList = []
for fc in fcList:
    if fc == "Lakes" or fc == "Streams":
        arcpy.Buffer_analysis(fc, fc + "Buffer", "1000 meters")
        bufferList.append(fc + "Buffer")

arcpy.Union_analysis(bufferList, "WaterBuffers")

You need to read/check your code closer because these are pretty simple mistakes.