1

I'm new to ArcPy and Python and have a very simple question. I'm trying to write a Python script in idle to extract the number of feature class files from a geodatabase. I can do it just fine in the console, but when I try to write a script, I get the following error:

Traceback (most recent call last):
  File "C:\Users\ihb\Documents\assignmente_7.py", line 22, in <module>
    for feature in fcList:
TypeError: 'NoneType' object is not iterable

Here is the code that is generating the error:

#Import arcpy and set output environments
import arcpy, sys
from arcpy import env
print "Please enter desired workspace in the 'Args' space: "
if sys.modules['idlelib']: sys.argv.extend(raw_input("Args: ").split())
workSpace = sys.argv[1]
env.workspace = workSpace
env.overwriteOutput = True

#Get Feature Classes
fcList = arcpy.ListFeatureClasses()
for feature in fcList: ### <-- **ERROR OCCURS HERE** <--####
    desc = arcpy.Describe(feature)
    print feature

I need to include the sys argument so that users can specify the workspace directory.

  • 3
    It doesn't appear that your problem is GIS-related. You should be checking that the sys.argv[1] value is valid before using it to set the workspace. – Vince Oct 11 '19 at 16:52
  • Thank you very much! – ihb Oct 11 '19 at 21:32
  • 1
    Did @Vince solve your issue? – Aaron Oct 12 '19 at 2:47
  • @Aaron yes he did, thank you! I was putting my workspace directory in quotation marks, and I just found out you don't do that sys.argv – ihb Oct 14 '19 at 1:14
1

It turns out that I was using quotation marks to specify my workspace directory. That was my issue. You can't do that with sys.argv, apparently. I'm new to Python, so I'm learning as I go!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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