0

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
5
  • You have a ) at the end of your workspace - remove it.
    – ianbroad
    Commented Jan 10, 2015 at 20:28
  • U used List object assignment as "fclList = arcpy.ListFeatureClasses()" but u recalled "fc in fcList:" it should be "fclList" then try.
    – Learner
    Commented Jan 10, 2015 at 21:04
  • Question: Does ESRI always update their new functions and then remove some of the functions when they upgrade their software ?
    – PROBERT
    Commented Jan 10, 2015 at 21:08
  • The question you asked is actually pure Python rather than ArcPy and so be aware that researching it at StackOverflow may have been a better option. Searching on your error message quickly found stackoverflow.com/questions/3887381/…
    – PolyGeo
    Commented Jan 11, 2015 at 0:06
  • @PolyGeo - will do !
    – PROBERT
    Commented Jan 11, 2015 at 0:33

1 Answer 1

1

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.

4
  • Yes, I do need to read very carefully. Thanks for the help!
    – PROBERT
    Commented Jan 10, 2015 at 21:06
  • @PROBERT no problem, it happens though. It can be hard to see those little mistakes in your own code.
    – ianbroad
    Commented Jan 10, 2015 at 21:14
  • Thanks. Is there a way you write a code other than IDE that does detect errors showing in colors ? Just thought I'd ask .
    – PROBERT
    Commented Jan 10, 2015 at 21:16
  • 2
    You might try using PyScripter. It has autocomplete functionality which is really nice. code.google.com/p/pyscripter
    – ianbroad
    Commented Jan 10, 2015 at 21:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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