<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Referencing Shapefiles in Python and Printing Shapefile Entries in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560628#M43867</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, that's correct. I think what Dan is getting at is that although ListFields returns an iterator, the field objects it's iterating can't be compared directly, you have to call the &lt;A href="http://resources.arcgis.com/en/help/main/10.2/018z/018z0000004n000000.htm"&gt;property of the field object&lt;/A&gt;; like with &lt;SPAN style="font-family: 'courier new', courier;"&gt;.name&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 08 Apr 2015 21:51:26 GMT</pubDate>
    <dc:creator>BlakeTerhune</dc:creator>
    <dc:date>2015-04-08T21:51:26Z</dc:date>
    <item>
      <title>Referencing Shapefiles in Python and Printing Shapefile Entries</title>
      <link>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560614#M43853</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am a complete Python novice and I have been searching and searching and so far, I am unable to find a straightforward answer to my question.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to write a statement that checks if a shapefile has a field "Area", and if not, make one. This is what I have:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;outline=&lt;SPAN style="color: #008000; font-weight: bold;"&gt;"LRoutline"&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;if &lt;SPAN style="color: #008000; font-weight: bold;"&gt;"Area"&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;SPAN style="color: #000080; font-weight: bold;"&gt;not in &lt;/SPAN&gt;outline:&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(outline, &lt;SPAN style="color: #008000; font-weight: bold;"&gt;"Area"&lt;/SPAN&gt;, &lt;SPAN style="color: #008000; font-weight: bold;"&gt;"FLOAT"&lt;/SPAN&gt;, &lt;SPAN style="color: #0000ff;"&gt;6&lt;/SPAN&gt;, &lt;SPAN style="color: #0000ff;"&gt;3&lt;/SPAN&gt;)&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P&gt;The If statement isn't working.&amp;nbsp; When I run it again, the code gets hung up because there is already a field named "Area".&amp;nbsp; Obviously, the code is not looking if there is a field named "Area" but rather it is looking for that string in the variable.&amp;nbsp; How do I reference the fields inside a shapefile within an If statement? &lt;EM&gt; outline.Area&lt;/EM&gt; doesn't work and neither does&lt;EM&gt; !Area!&lt;/EM&gt;.&amp;nbsp; I have tried the SearchCursor thing using the following code and it outputs &lt;EM&gt;&amp;lt;Cursor object at 0x137ed0f0[0x13587f80]&amp;gt;, &lt;/EM&gt;and I don't know what that means.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;arcpy.SearchCursor(outline)&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P&gt;Furthermore, I want to sum the areas in that Area field after they are calculated, so I need to be able to reference the field, right?&amp;nbsp; I looked at the &lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//00080000001z000000"&gt;arcpy.Statistics_analysis() function&lt;/A&gt; and I need to create a whole separate table to pull one value from the shapefile?&amp;nbsp; That's not required to view the summary statistics in the ArcGIS GUI (right click on field in attribute table-&amp;gt; Summary...).&amp;nbsp; Is there a less cluttered way to sum the entries in a shapefile field in Python? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have downloaded the &lt;A href="https://pypi.python.org/pypi/pyshp#reading-records"&gt;shapefile package &lt;/A&gt;but that doesn't seem to fit what I need either.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2015 20:35:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560614#M43853</guid>
      <dc:creator>RachaelJohnson</dc:creator>
      <dc:date>2015-04-08T20:35:30Z</dc:date>
    </item>
    <item>
      <title>Re: Referencing Shapefiles in Python and Printing Shapefile Entries</title>
      <link>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560615#M43854</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Make your list of fields using &lt;A href="http://resources.arcgis.com/en/help/main/10.2/#/ListFields/03q30000001t000000/"&gt;ListFields&lt;/A&gt;. If you're first learning cursors, you should skip to using the &lt;A href="http://resources.arcgis.com/en/help/main/10.2/#/SearchCursor/018w00000011000000/"&gt;arcpy.da.SearchCursor&lt;/A&gt;. Both links contain examples at the bottom.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2015 20:38:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560615#M43854</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2015-04-08T20:38:36Z</dc:date>
    </item>
    <item>
      <title>Re: Referencing Shapefiles in Python and Printing Shapefile Entries</title>
      <link>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560616#M43855</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It looks like you spent a lot of time formatting your Python code to highlight syntax like the IDE. There's a handy way to let the GeoNet forums do that for you! &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migration-blogpost/1070"&gt;Posting Code blocks in the new GeoNet&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2015 20:41:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560616#M43855</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2015-04-08T20:41:39Z</dc:date>
    </item>
    <item>
      <title>Re: Referencing Shapefiles in Python and Printing Shapefile Entries</title>
      <link>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560617#M43856</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I actually just copy/pasted from PyCharm and it looked like that without any effort! But thank you.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2015 20:43:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560617#M43856</guid>
      <dc:creator>RachaelJohnson</dc:creator>
      <dc:date>2015-04-08T20:43:43Z</dc:date>
    </item>
    <item>
      <title>Re: Referencing Shapefiles in Python and Printing Shapefile Entries</title>
      <link>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560618#M43857</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fc = r'PathToLayer\LayerNamel'
field_names = [f.name for f in arcpy.ListFields(fc)]
if 'Area' not in field_names:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(fc, "Area", "FLOAT", 6, 3)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Resources:&lt;/P&gt;&lt;P&gt;List Fields &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//018v00000012000000" title="http://resources.arcgis.com/en/help/main/10.2/index.html#//018v00000012000000" rel="nofollow noopener noreferrer" target="_blank"&gt;ArcGIS Help (10.2, 10.2.1, and 10.2.2)&lt;/A&gt;&lt;/P&gt;&lt;P&gt;AddFields &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//001700000047000000" title="http://resources.arcgis.com/en/help/main/10.2/index.html#//001700000047000000" rel="nofollow noopener noreferrer" target="_blank"&gt;ArcGIS Help (10.2, 10.2.1, and 10.2.2)&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:11:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560618#M43857</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-12T00:11:35Z</dc:date>
    </item>
    <item>
      <title>Re: Referencing Shapefiles in Python and Printing Shapefile Entries</title>
      <link>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560619#M43858</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you so much for pointing me to ListFields and arcpy.da.SearchCursor!&amp;nbsp; How is da.SearchCursor different from regular SearchCursor?&amp;nbsp; &lt;/P&gt;&lt;P&gt;Anyway, I will see what I can do with these two commands. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2015 20:57:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560619#M43858</guid>
      <dc:creator>RachaelJohnson</dc:creator>
      <dc:date>2015-04-08T20:57:11Z</dc:date>
    </item>
    <item>
      <title>Re: Referencing Shapefiles in Python and Printing Shapefile Entries</title>
      <link>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560620#M43859</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Data module cursors are much faster and provide access to geometry tokens. Probably other unknown benefits. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2015 21:01:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560620#M43859</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2015-04-08T21:01:07Z</dc:date>
    </item>
    <item>
      <title>Re: Referencing Shapefiles in Python and Printing Shapefile Entries</title>
      <link>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560621#M43860</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To expand on what &lt;A href="https://community.esri.com/migrated-users/7306" target="_blank"&gt;James Crandall&lt;/A&gt; posted and accomplish your second task of getting the total area for all features in the shapefile, you could use a SearchCursor like &lt;A href="https://community.esri.com/migrated-users/19932" target="_blank"&gt;Darren Wiens&lt;/A&gt; mentioned, or the &lt;A href="http://resources.arcgis.com/en/help/main/10.2/0008/00080000001z000000.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;Summary Statistics&lt;/A&gt; that you mentioned yourself. If you go with the Summary Statistics, you could use &lt;A href="http://resources.arcgis.com/en/help/main/10.1/002w/002w0000005s000000.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;in-memory workspace&lt;/A&gt; for the output table, but you'd still have to use a SearchCursor to get the values out of it, so you might as well just do your own adding.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

fc = r'PathToLayer\LayerNamel'
field_names = [f.name for f in arcpy.ListFields(fc)]
if 'Area' not in field_names:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(fc, "Area", "FLOAT", 6, 3)

arcpy.CalculateField_management(
&amp;nbsp;&amp;nbsp;&amp;nbsp; fc,
&amp;nbsp;&amp;nbsp;&amp;nbsp; "Area",
&amp;nbsp;&amp;nbsp;&amp;nbsp; "!SHAPE.area!",
&amp;nbsp;&amp;nbsp;&amp;nbsp; "PYTHON_9.3",
)

fcAreas = [row[0] for row in arcpy.da.SearchCursor(fc, ["Area"])]
print sum(fcAreas)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;EDIT:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;After thinking about this, it might actually be better if you used Summary Statistics instead of calculating the field because if the geometry of the features change, the Area field will not get updated unless you run this code again. The values in the Area field could be misleading.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:11:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560621#M43860</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-12-12T00:11:37Z</dc:date>
    </item>
    <item>
      <title>Re: Referencing Shapefiles in Python and Printing Shapefile Entries</title>
      <link>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560622#M43861</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The regular (non &lt;SPAN style="font-family: 'courier new', courier;"&gt;da&lt;/SPAN&gt;) cursors are also older and will eventually get depreciated by Esri. The new ones are more future proof.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2015 21:17:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560622#M43861</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2015-04-08T21:17:11Z</dc:date>
    </item>
    <item>
      <title>Re: Referencing Shapefiles in Python and Printing Shapefile Entries</title>
      <link>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560623#M43862</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you!&amp;nbsp; Would you mind helping me understand that code? What is the purpose of the row[0]?&amp;nbsp; Is it telling the computer to start with the first entry in the "Area" field? Or is it creating a list? Or something else?&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2015 21:26:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560623#M43862</guid>
      <dc:creator>RachaelJohnson</dc:creator>
      <dc:date>2015-04-08T21:26:07Z</dc:date>
    </item>
    <item>
      <title>Re: Referencing Shapefiles in Python and Printing Shapefile Entries</title>
      <link>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560624#M43863</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Rachel .... for a python moment...strings are iterables, just as lists are.&amp;nbsp; To see where the pitfalls can arise, examine the following code segments:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; case_1='LRoutline'
&amp;gt;&amp;gt;&amp;gt; for i in case_1: print i
&amp;gt;&amp;gt;&amp;gt; print 'line' in case_1
&amp;gt;&amp;gt;&amp;gt; print 'Area' in case_1&lt;/PRE&gt;&lt;P&gt;Line 1&amp;nbsp; case_1 is defined as your input field&lt;/P&gt;&lt;P&gt;Line 2&amp;nbsp; let's demonstrate that it is an interable...result&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; for i in case_1: print i
... 
L
R
o
u
t
l
i
n
e
&amp;gt;&amp;gt;&amp;gt;&lt;/PRE&gt;&lt;P&gt;Line 3 let's see if sequences can be found there... result&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; print 'line' in case_1
True
&amp;gt;&amp;gt;&amp;gt;&lt;/PRE&gt;&lt;P&gt;Line 4&amp;nbsp; let's assume you think it is a file and want the Area field&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; print 'Area' in case_1
False
&amp;gt;&amp;gt;&amp;gt;&lt;/PRE&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now for a more practical example...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; import arcpy
&amp;gt;&amp;gt;&amp;gt; shp_file = 'c:/temp/cube.shp'
&amp;gt;&amp;gt;&amp;gt; for field in arcpy.ListFields(shp_file): print field.name
... 
FID
Shape
Id
&amp;gt;&amp;gt;&amp;gt; 'Id' in arcpy.ListFields(shp_file)
False
&amp;gt;&amp;gt;&amp;gt;&lt;/PRE&gt;&lt;P&gt;Now the above produces a false because as pointed out in a subsequent post you need the field.name not the field itself.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; shp_file = 'c:/temp/cube.shp' 
&amp;gt;&amp;gt;&amp;gt; field_names = [field.name for field in arcpy.ListFields(shp_file)]
&amp;gt;&amp;gt;&amp;gt; field_names
[u'FID', u'Shape', u'Id']
&amp;gt;&amp;gt;&amp;gt; 'Id' in field_names
True
&amp;gt;&amp;gt;&amp;gt;&lt;/PRE&gt;&lt;P&gt;Hope this helps for the future.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:11:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560624#M43863</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-12T00:11:40Z</dc:date>
    </item>
    <item>
      <title>Re: Referencing Shapefiles in Python and Printing Shapefile Entries</title>
      <link>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560625#M43864</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It's referring to an index of the list of values in the &lt;SPAN style="font-family: 'courier new', courier;"&gt;row&lt;/SPAN&gt; variable. The search cursor returns each row as a &lt;A href="https://docs.python.org/2/tutorial/datastructures.html#tuples-and-sequences"&gt;tuple&lt;/A&gt; (which is a kind of list in Python). The number of&amp;nbsp; indexes in that tuple is equal to the number of fields you used in the arguments to create the cursor. In this case, there's only one field so it returns a tuple with only one value as&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14285289987739062 jive_text_macro" data-renderedposition="71_8_912_16" jivemacro_uid="_14285289987739062"&gt;&lt;P&gt;(23456.93426,)&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;The comma in there is important because a single item tuple still has a comma afterwards (unlike a list).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So when I say row[0], it's getting the value of the first item, which is also known as index 0. Index 1 would be the second item, and so on. If I just said row, it would return all field values in the whole row as a tuple instead of just the single value as a number.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2015 21:40:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560625#M43864</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2015-04-08T21:40:25Z</dc:date>
    </item>
    <item>
      <title>Re: Referencing Shapefiles in Python and Printing Shapefile Entries</title>
      <link>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560626#M43865</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: #f6f6f6;"&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/SPAN&gt;&lt;SPAN class="string" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: blue; background-color: #f6f6f6;"&gt;'Id'&lt;/SPAN&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000; background-color: #f6f6f6;"&gt; &lt;/SPAN&gt;&lt;SPAN class="keyword" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #006699; background-color: #f6f6f6;"&gt;in&lt;/SPAN&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000; background-color: #f6f6f6;"&gt; arcpy.ListFields(shp_file) &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I don't understand why that returns False.&amp;nbsp; Is it because arcpy.ListFields(shp_file) just returns: [&amp;lt;Field object at 0x5498250[0x5444ad0]&amp;gt;, &amp;lt;Field object at 0x5498110[0x5444908]&amp;gt;, &amp;lt;Field object at 0x54981b0[0x5444a40]&amp;gt;, &amp;lt;Field object at 0x5498190[0x5444848]&amp;gt;] ? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2015 21:45:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560626#M43865</guid>
      <dc:creator>RachaelJohnson</dc:creator>
      <dc:date>2015-04-08T21:45:56Z</dc:date>
    </item>
    <item>
      <title>Re: Referencing Shapefiles in Python and Printing Shapefile Entries</title>
      <link>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560627#M43866</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So if I had &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;arcpy.da.SearchCursor(outline, outFld)])&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;instead of &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;arcpy.da.SearchCursor(outline, [&lt;SPAN style="color: #008000; font-weight: bold;"&gt;"Area"&lt;/SPAN&gt;])]),&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would have to change the code to &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;siteArea= &lt;SPAN style="color: #000080;"&gt;sum&lt;/SPAN&gt;([row[&lt;SPAN style="color: #0000ff;"&gt;3&lt;/SPAN&gt;] &lt;SPAN style="color: #000080; font-weight: bold;"&gt;for &lt;/SPAN&gt;row &lt;SPAN style="color: #000080; font-weight: bold;"&gt;in &lt;/SPAN&gt;arcpy.da.SearchCursor(outline, [outFld])])&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if "Area" was the fourth field in the shapefile? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2015 21:51:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560627#M43866</guid>
      <dc:creator>RachaelJohnson</dc:creator>
      <dc:date>2015-04-08T21:51:08Z</dc:date>
    </item>
    <item>
      <title>Re: Referencing Shapefiles in Python and Printing Shapefile Entries</title>
      <link>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560628#M43867</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, that's correct. I think what Dan is getting at is that although ListFields returns an iterator, the field objects it's iterating can't be compared directly, you have to call the &lt;A href="http://resources.arcgis.com/en/help/main/10.2/018z/018z0000004n000000.htm"&gt;property of the field object&lt;/A&gt;; like with &lt;SPAN style="font-family: 'courier new', courier;"&gt;.name&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2015 21:51:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560628#M43867</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2015-04-08T21:51:26Z</dc:date>
    </item>
    <item>
      <title>Re: Referencing Shapefiles in Python and Printing Shapefile Entries</title>
      <link>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560629#M43868</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes. Since I don't know exactly what &lt;SPAN style="font-family: 'courier new', courier;"&gt;outFld&lt;/SPAN&gt; contains, I'll draft an example...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fc = r'PathToLayer\LayerNamel'
fields = ["ObjectID", "SomeField", "Area"]

with arcpy.da.SearchCursor(fc, fields) as sCursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in sCursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row&amp;nbsp; ## Prints tuple of all field values
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[0]&amp;nbsp; ## Prints single field value in first field, ObjectID
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[1]&amp;nbsp; ## Prints single field value in second field, SomeField
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[2]&amp;nbsp; ## Prints single field value in third field, Area&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The example here using the &lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;A href="http://effbot.org/zone/python-with-statement.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;with&lt;/A&gt;&lt;/SPAN&gt; statement is the more typical way you'll see the cursors being used. The example I posted earlier uses the cursor in what's called &lt;A href="https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions" rel="nofollow noopener noreferrer" target="_blank"&gt;list comprehension&lt;/A&gt;, which uses shorthand code to create a list from an iterable. The code from &lt;A href="https://community.esri.com/migrated-users/7306" target="_blank"&gt;James Crandall&lt;/A&gt; also uses list comprehension to create a list of field names.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:11:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560629#M43868</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-12-12T00:11:43Z</dc:date>
    </item>
    <item>
      <title>Re: Referencing Shapefiles in Python and Printing Shapefile Entries</title>
      <link>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560630#M43869</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It would depend on what the variable outFld contains.&amp;nbsp; If it contains a list of fields of which "Area" is the 4th field in the list, then yes you would use row[3].&amp;nbsp; However, if it only contained a single field, "Area", then you would use row[0].&amp;nbsp; Generally it is good practice to only put the fields into a cursor that you will actually be using to check or update data, since it will run faster if it needs values from 1-2 fields then from 20. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2015 22:03:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560630#M43869</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2015-04-08T22:03:13Z</dc:date>
    </item>
    <item>
      <title>Re: Referencing Shapefiles in Python and Printing Shapefile Entries</title>
      <link>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560631#M43870</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Awesome, thank you for sticking it out with me and answering my questions.&amp;nbsp; Today is my first day coding with Python after only doing the "Python for Everyone" tutorial in the Esri training modules.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I wanted to print the second field value in the second field, would it be&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: inherit; color: black; font-weight: inherit; font-size: 9pt !important; font-style: inherit;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="background-color: inherit; color: black; font-weight: inherit; font-size: 9pt !important; font-style: inherit;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="_jivemacro_uid_14285306837723874 jive_macro_code jive_text_macro" data-renderedposition="112.390625_8_882_108" jivemacro_uid="_14285306837723874"&gt;&lt;OL class="dp-py" start="1" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #5c5c5c; margin-bottom: 1px !important; margin-left: 45px !important;"&gt;&lt;LI&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;fc = r&lt;/SPAN&gt;&lt;SPAN class="string" style="font-weight: inherit; font-style: inherit; color: blue; font-size: 9pt !important; background-color: inherit;"&gt;'PathToLayer\LayerNamel'&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;fields = [&lt;SPAN class="string" style="font-weight: inherit; font-style: inherit; color: blue; font-size: 9pt !important; background-color: inherit;"&gt;"ObjectID"&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;, &lt;/SPAN&gt;&lt;SPAN class="string" style="font-weight: inherit; font-style: inherit; color: blue; font-size: 9pt !important; background-color: inherit;"&gt;"SomeField"&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;, &lt;/SPAN&gt;&lt;SPAN class="string" style="font-weight: inherit; font-style: inherit; color: blue; font-size: 9pt !important; background-color: inherit;"&gt;"Area"&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;]&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;with arcpy.da.SearchCursor(fc, ["SomeField"]) as sCursor:&amp;nbsp; &lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; font-size: 9pt !important; background-color: inherit;"&gt;for&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt; row &lt;/SPAN&gt;&lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; font-size: 9pt !important; background-color: inherit;"&gt;in&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt; sCursor:&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; font-size: 9pt !important; background-color: inherit;"&gt;print&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt; row[1]&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2015 22:07:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560631#M43870</guid>
      <dc:creator>RachaelJohnson</dc:creator>
      <dc:date>2015-04-08T22:07:29Z</dc:date>
    </item>
    <item>
      <title>Re: Referencing Shapefiles in Python and Printing Shapefile Entries</title>
      <link>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560632#M43871</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Almost, but not quite. That would give you an error because there is nothing at index 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The field_names parameter for the &lt;A href="http://resources.arcgis.com/en/help/main/10.2/018w/018w00000011000000.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;SearchCursor&lt;/A&gt; can be declared as a list directly in the call to the method or you can assign it to a variable ahead of time and then pass that variable containing the field names list as the field_names parameter; &lt;STRONG&gt;don't do both&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In your example, you've created a &lt;SPAN style="font-family: 'courier new', courier;"&gt;fields&lt;/SPAN&gt; variable that contains a list of field name strings. Then, when you create the cursor, you explicitly tell it to use only "SomeField". What you'd get are rows as a single item tuple with one field value for SomeField. If you instead wanted access to the field values from all three fields you specified in the &lt;SPAN style="font-family: 'courier new', courier;"&gt;fields&lt;/SPAN&gt; variable, create the cursor with &lt;SPAN style="font-family: 'courier new', courier;"&gt;fields&lt;/SPAN&gt; as the field_names parameter (instead of just ["SomeField"] like I did in the &lt;A _jive_internal="true" href="https://community.esri.com/message/492109#492109" target="_blank"&gt;example just before&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;These two examples would both do the same thing: print the field value of SomeField for every row in the feature class.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fc = r'PathToLayer\LayerNamel'
fields = ["ObjectID", "SomeField", "Area"]

with arcpy.da.SearchCursor(fc, fields) as sCursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in sCursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[1]&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fc = r'PathToLayer\LayerNamel'

with arcpy.da.SearchCursor(fc, ["SomeField"]) as sCursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in sCursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[0]&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Choose one or the other, but don't combine them both.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:11:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560632#M43871</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-12-12T00:11:45Z</dc:date>
    </item>
    <item>
      <title>Re: Referencing Shapefiles in Python and Printing Shapefile Entries</title>
      <link>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560633#M43872</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Blake...I edited my post to reflect this&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2015 23:26:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/referencing-shapefiles-in-python-and-printing/m-p/560633#M43872</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-04-08T23:26:48Z</dc:date>
    </item>
  </channel>
</rss>

