Select to view content in your preferred language

Python script from ModelBuilder - mysterious bits of code at the beginning and end

947
0
06-16-2023 05:12 PM
Labels (2)
IlkaIllers1
Frequent Contributor

Hello!

I exported a model from modelbuilder to python and am confused about these bits at the beginning: 

from sys import argv
def FeatureClassGenerator(workspace, wild_card, feature_type, recursive) :
    with arcpy.EnvManager(workspace = workspace):

        dataset_list = [""]
        if recursive:
            datasets = arcpy.ListDatasets()
            dataset_list.extend(datasets)

        for dataset in dataset_list:
            featureclasses = arcpy.ListFeatureClasses(wild_card, feature_type, dataset)
            for fc in featureclasses:
                yield os.path.join(workspace, dataset, fc), fc

 

as well as at the end:

if __name__ == '__main__':
    # Global Environment settings
    with arcpy.EnvManager():
        Model(*argv[1:])

I can remove the one at the beginning without seeing an impact, but if I remove the one at the end, the model doesn't run in the python IDE. I never would have written anything like this had I started from scratch. What is happening here? Do I need this in other scripts too? 

Thank you!

0 Kudos
0 Replies