5

Following up on Using FeatureClassToFeatureClass from list to concatenated list?

The error I get is "Parsing error SyntaxError: invalid syntax (line 10)".

Using the methods from above I am unable to get following to work.

I want to delete selected feature classes using filtered list. This example is a simplified version of what I need.

# Import arcpy module
import os, fnmatch, arcpy
arcpy.env.workspace = r"D:\_StuData\GIS\Projects\PersonalProjects\Product\test.gdb"

# variables:
fcs = arcpy.ListFeatureClasses() 
filtered = fnmatch.filter(fcs, '*copy')

# Delete selected fcs
for fc in filtered
    arcpy.Delete_management(fc)
3
  • 1
    What is the error? Maybe filtered isn't a list? You might also do well to put the delete inside of an "if arcpy.Exists()" block! Commented Jan 19, 2016 at 17:15
  • Parsing error SyntaxError: invalid syntax (line 10)
    – Stu
    Commented Jan 19, 2016 at 17:25
  • Please edit your question to include requested clarifications such as this.
    – PolyGeo
    Commented Jan 19, 2016 at 19:00

1 Answer 1

9

After you supplied the error, I noticed you didn't use a colon at the end of line 10. You should replace lines 10 and 11 with the following lines.

for fc in filtered:
  if arcpy.Exists(fc):
    arcpy.Delete_management(fc)

Chances are you'd never have it try to delete one that doesn't exist but this way, it keeps deleting if it DOES find one that doesn't exist (maybe you or someone else deleted it before it got there). I find that to be a good practice.

0

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.