If a feature class is in list  ??? Process

437
2
02-05-2013 10:53 AM
davidmetzler
New Contributor II
Hello,
   I am running into a few errors trying to do something seemingly simple. I would like to generate a list of feature classes in a set of subfolders. If there is a specific feature class name in the list I would like to append this data to a dataset. I would like this to work for any feature class with the specific name as there will be many with the same name in different folders. I am able to list the Feature classes just fine but I cant get the syntax for finding the specific ones and appending them.
This is what I have:
def main():
    try:
        import arcpy, sys, traceback, os, glob, shutil
        arcpy.env.overwriteOutput = True
        log = r'Q:\1-EMPLOYEE INBOX\David\downloads\logSurveyData.txt'
        masterFolder = r"Q:\Field Data\P.M.M\TO_PAM"
        outFolder = r"P:\Projects\SurveyData\DATA\Master.gdb\SMON"
        dst = r'Q:\GIS\Field_Data\z_archive'
        
     #   shutil.copytree(masterFolder, dst + time.strftime('%m_%d_%y'))
        

        #collect a list of subfolders in master folder
        arcpy.env.workspace = masterFolder
        arcpy.ListWorkspaces('','Folder')
        subfolderLst = arcpy.ListWorkspaces('','Folder')
        print subfolderLst
        for subfolder in subfolderLst:
            arcpy.env.workspace = subfolder
            fcLst = arcpy.ListFeatureClasses()
            print fcLst
            
            
            for fc in fcLst("SectMon_PLSS_"):
                    arcpy.Append_management(fc, outFolder)

    except:
        print arcpy.GetMessages()
            # Get the traceback object '"' + wildcard + '"'
        tb = sys.exc_info()[2]
        tbinfo = traceback.format_tb(tb)[0]

        # Concatenate information together concerning the error into a
# message string
        pymsg = tbinfo + "\n" + str(sys.exc_type)+ ": " + str(sys.exc_value)

# Return python error messages for use with a script tool
        arcpy.AddError(pymsg)

# Print Python error messages for use in Python/PythonWin
        print pymsg
    

if __name__ == '__main__':
    main()



Right now the error I am seeing is this
<type 'exceptions.TypeError'>: 'list' object is not callable


That being said even if the list worked I dont know if it would amend.

Thanks!
Tags (2)
0 Kudos
2 Replies
MathewCoyle
Frequent Contributor
You have already created the fcList so you cannot call it since it is a list not a function. If you want to limit by a wildcard you would need to do that on this line.
fcLst = arcpy.ListFeatureClasses("SectMon_PLSS_*")

What is the name of the feature class you want to append? You can modify the wildcard to be a particular suffix if they change or a static string if they are exactly the same.
0 Kudos
curtvprice
MVP Esteemed Contributor
The Iterate Feature Classes tool in ModelBuilder may get you there faster than a complex python script. It does all the nested paths for you and returns a list of feature classes based on a wild card.

If you want to stick with Python and can use 10.1 SP 1 or later, check out arcpy.da.walk.

If you don't use the tools above and stick with your current script, might want to mention it would be far more efficient to do a single append operation. Note, the output of Append must an existing feature class, not a folder. (Merge can be used to create a new feature class.)

fcs = []
    ...do your looping...
        fcs.append(fc)
arcpy.Append_management(fcs,outFC,"NO_TEST") 
0 Kudos