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.
Assuming ArcGIS desktop and Python 2.x:
<SPAN class="keyword token">import</SPAN> arcpy fc <SPAN class="operator token">=</SPAN> <SPAN class="string token">'Your_Feature_Class'</SPAN> fields <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'Fields'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'You'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'Want'</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">,</SPAN>fields<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> cursor<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> cursor<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">print</SPAN> row<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
If using ArcGIS Pro with python 3.x,change
<SPAN class="keyword token">print</SPAN> row <SPAN class="comment token"># to</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Thank you! Say I wanted to pull a certain value out of the field using the 'where clause'. How is that done?
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.
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.