NoneType object is not iterable

6189
12
09-18-2018 03:51 PM
JeremiahGbolagun1
New Contributor

Hi there, when I run this code in PyScripter IDE I received this error 'NoneType is not iterable'.

Can you please help to address this problem.

Regards,

import arcpy

#Set geoprocessing environments
arcpy.env.workspace = ("C:\EsriTraining\Python10_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()
arcpy.Buffer_analysis(fc, fc + "Buffer", "1000 meters")
bufferList.append(fc + "Buffer")
arcpy.Union_analysis(bufferList, "WaterBuffers")

0 Kudos
12 Replies
DarrenWiens2
MVP Honored Contributor

Please format your code for readability: /blogs/dan_patterson/2016/08/14/script-formatting 

I assume your code is failing at:

for fc in fcList:‍‍

Try printing fcList to see if it's empty. I suspect it's because your path isn't a raw string (backslashes in paths are bad). Try:

arcpy.env.workspace = r"C:\EsriTraining\Python10_0\Data\SanJuan.gdb"‍‍

If none of this helps, please format your code and indicate where the error occurs.

edit: this line is surely wrong:

arcpy.Buffer()
JeremiahGbolagun1
New Contributor

I added r and yet the same error occurred.

0 Kudos
DanPatterson_Retired
MVP Emeritus

adding the r is a start, but you didn't see Darren's statement

arcpy.Buffer()

that line will fail.  In fact, in its current state you code will fail because it is not formatted properly.

Now the error message indicates that there are no featureclasses in your featureclass list

ListFeatureClasses—ArcPy Functions | ArcGIS Desktop 

or it failed because of the arcpy.Buffer() line, 

0 Kudos
JeremiahGbolagun1
New Contributor

This code was written in one of your online courses called “Python Scripting for Geoprocessing Workflows” Can you please help to rewrite the code.

0 Kudos
JeremiahGbolagun1
New Contributor

When I removed the ‘arcpy.Buffer() the code failed at “for fc in fcList:

0 Kudos
DanPatterson_Retired
MVP Emeritus

put a print statement before that line and see if there is anything there to cycle through

ie

print("found.... {}".format(fcList))

0 Kudos
JeremiahGbolagun1
New Contributor

This is the outcome Dan.

0 Kudos
DanPatterson_Retired
MVP Emeritus

so the print statement? did you put it in?

0 Kudos
JeremiahGbolagun1
New Contributor

Yes I did. Did you see the print screen image I sent to you Dan.

0 Kudos