0

I want to combine two FOR LOOPS but I have no idea how. It should give me in each TYPE Layer "under" Layers, where are new Layers for each MONTH (see picture)

enter image description here

The two loops in itself works.

# MakeFeatureLayer_management for each whale/dolphin type
whale_names = [
"Atlantic Spotted Dolphin",
"Pilot Whale",
"Bottlenose Dolphin",
"Rough-Toothed Dolphin",
"Bryde´s Whale",
"Common Dolphin"]

 for name in whale_names:
     arcpy.MakeFeatureLayer_management("Sichtungen95-14", "test-" + name, "SPECIES = '%s'" % (name))
     # MakeFeatureLayer_management for each month
 for month in range (01,12):          
     arcpy.MakeFeatureLayer_management ("Sichtungen95-14", "test%s" % month, "DATE >= date'01.01.1995' AND DATE < date'01.01.2015' AND EXTRACT(MONTH FROM DATE) = %s" % (month))
1

Simply indent your second for loop, and it will iterate the twelve months for each iteration of your initial loop.

for name in whale_names:
    arcpy.MakeFeatureLayer_management("Sichtungen95-14", "test-" + name, "SPECIES = '%s'" % (name))
    # MakeFeatureLayer_management for each month
    for month in range (01,12):          
        arcpy.MakeFeatureLayer_management ("Sichtungen95-14", "test%s" % month, "DATE >= date'01.01.1995' AND DATE < date'01.01.2015' AND EXTRACT(MONTH FROM DATE) = %s" % (month))

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.