From the course: Learning ArcGIS Python Scripting (2018)
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Nested loops - ArcGIS Tutorial
From the course: Learning ArcGIS Python Scripting (2018)
Nested loops
- [Instructor] I'm gonna show how Python loops can be nested, which means putting a loop inside another loop. The indention is what controls the loop structure. Everything that is inside the loop must be indented with the same number of spaces. Here I have a for each loop that contains a for each loop that contains a for each loop. I'm gonna write a script to make a list of all the label classes that are used in the layers of a map document. This will involve some nested loops. First we'll need to get the map document. And then we'll need to get the data frames. And then we'll need to get the layers. And finally we'll be able to get to the label classes. I've got a script already written that does part of the work for us. This script lists the data frames in a map document. First it creates the map document object and saves it to the mxd variable. Next it uses arcpy.mapping.ListDataFrames to create the list of data frame objects, which it saves to the variable list of data frames…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.