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")
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()
I added r and yet the same error occurred.
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,
This code was written in one of your online courses called “Python Scripting for Geoprocessing Workflows” Can you please help to rewrite the code.
When I removed the ‘arcpy.Buffer() the code failed at “for fc in fcList:
put a print statement before that line and see if there is anything there to cycle through
ie
print("found.... {}".format(fcList))
so the print statement? did you put it in?
Yes I did. Did you see the print screen image I sent to you Dan.