Select to view content in your preferred language

How do I display an attribute table field using a search cursor?

5362
3
Jump to solution
04-04-2018 12:46 PM
JacksonBrown
Emerging Contributor

I want to use arc py and the search cursor tool to display values from a field in my attribute table called 'NSA' inside a layer called 'Receiver_NSA_Label_Join'.

What is the code that I use to do this? Everything I have tried hasn't worked.

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
JoeBorgione
MVP Emeritus

Assuming ArcGIS desktop and Python 2.x:

import arcpy

fc = 'Your_Feature_Class'
fields = ['Fields','You','Want']

with arcpy.da.SearchCursor(fc,fields) as cursor:
    for row in cursor:
        print row‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 If using ArcGIS Pro with python 3.x,change 

print row
# to
print(row)‍‍‍
That should just about do it....

View solution in original post

0 Kudos
3 Replies
JoeBorgione
MVP Emeritus

Assuming ArcGIS desktop and Python 2.x:

import arcpy

fc = 'Your_Feature_Class'
fields = ['Fields','You','Want']

with arcpy.da.SearchCursor(fc,fields) as cursor:
    for row in cursor:
        print row‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 If using ArcGIS Pro with python 3.x,change 

print row
# to
print(row)‍‍‍
That should just about do it....
0 Kudos
JacksonBrown
Emerging Contributor

Thank you! Say I wanted to pull a certain value out of the field using the 'where clause'. How is that done?

0 Kudos
RichardFairhurst
MVP Honored Contributor

If you are trying to use python to display labels on a map that get data from a related table in a one-to-many or many-to-many relationship then take a look at my Creating Labels with Related Table Data Blog.

0 Kudos