I'm getting an IndexError saying it's out of range. But the Westerville dataframe is the first one and I'm using 0 to refer to it. After I run the program the cursor is at the end of the bolded line. What is Python trying to tell me?
mxd = arcpy.mapping.MapDocument(r"E:\EsriTraining\ArcPy\MapScripting\Exercise3\Westerville.mxd")
# return a list of all data frames in the mapping doc and assign it to df
df = arcpy.mapping.ListDataFrames(mxd)
lyr = arcpy.mapping.ListLayers(mxd, " ", df)
Solved! Go to Solution.
An index in Python refers to a position within an ordered list . This error basically means you are trying to access a value at a List index which is out of bounds i.e greater than the last index of the list or less than the least index in the list. So the first element is 0, second is 1, so on. So if there are n elements in a list, the last element is n-1 . If you try to access the empty or None element by pointing available index of the list, then you will get the "List index out of range " error. To solve this error, you should make sure that you're not trying to access a non-existent item in a list.