Select to view content in your preferred language

Python Terms Question

4037
10
06-06-2012 08:35 AM
SamanthaM
Emerging Contributor
Learning ArcPy, just trying to familiarize myself with the terms. In the below image I believe I have identified everything correctly, except what "lyr" represents.

[ATTACH=CONFIG]14975[/ATTACH]

The icon ArcGIS displays is a purple note stack. I am not sure what the term for this is. For example the term "For" is a statement, I believe, so what is the term for Lyr?

Here is another example
[ATTACH=CONFIG]14976[/ATTACH]
0 Kudos
10 Replies
by Anonymous User
Not applicable
Original User: dkwiens

From the Python documentation (very useful):

"The for statement in Python differs a bit from what you may be used to in C or Pascal. Rather than always iterating over an arithmetic progression of numbers (like in Pascal), or giving the user the ability to define both the iteration step and halting condition (as C), Python�??s for statement iterates over the items of any sequence (a list or a string), in the order that they appear in the sequence."

So, in your first example, "lyr" would be an "item", I guess. It's the "thing" in a bunch of "things".
0 Kudos
SamanthaM
Emerging Contributor
Actually it looks like the proper term for this is method. Can anyone confirm?
0 Kudos
by Anonymous User
Not applicable
Original User: dkwiens

I'm not sure what the technical term is (possibly "object"), but the purple note stack means "it's something the Python window knows about". I can only assume that you assigned something to the variable "lyr" before your first example, so the window knows what "lyr" is. If it's a string and you type "lyr." it will give you a list of properties and methods available to strings (capitalize, center, count, etc.). If you start typing "mxd." in your second example, it knows mxd is a map document, so it gives you properties and methods available to a map document.
0 Kudos
MathewCoyle
Honored Contributor
I believe it would be object not method.
0 Kudos
by Anonymous User
Not applicable
Original User: mnakleh

Objects in Python have:

  • Methods (i.e. functions that do things.)

  • Attributes (i.e. properties of the object itself)


In your example, calling ListLayers returns a list of the layer objects of the MapDocument ArcGIS page on layer objects
One of the attributes of this object is name. The object also has methods, like save (to save a layer file.)
0 Kudos
SamanthaM
Emerging Contributor
Thanks everyone.

I have an additional question, but not related terms.

For the code in this script it renames a legend element on the map. My question is what purpose does the [0] serve in making the code work/ what purpose does it serve? Please see image below for a clear picture of the issue.

[ATTACH=CONFIG]14995[/ATTACH]
0 Kudos
by Anonymous User
Not applicable
Original User: dkwiens

*ahem* from the help *ahem*
ListLayoutElements always returns a Python list object even if only one page element is returned. In order to return an element object, an index value must be used on the list (e.g., elm = arcpy.mapping.ListLayoutElements(mxd)[0]).

[0] means the first in the list (ie. an individual Layout Element object). If you leave it off, it returns a list of Layout Elements.
0 Kudos
MathewCoyle
Honored Contributor
Thanks everyone.

I have an additional question, but not related terms.

For the code in this script it renames a legend element on the map. My question is what purpose does the [0] serve in making the code work/ what purpose does it serve? Please see image below for a clear picture of the issue.

[ATTACH=CONFIG]14995[/ATTACH]


The [0] assigns the first index value to the variable. Without that index reference there it returns a list instead of a single object.
0 Kudos
by Anonymous User
Not applicable
Original User: SamanthaM

*ahem* from the help *ahem*

[0] means the first in the list (ie. an individual Layout Element object). If you leave it off, it returns a list of Layout Elements.


Sorry about that, I figured the help section of python within ArcGIS would display that.

[ATTACH=CONFIG]14999[/ATTACH]
0 Kudos