<?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 str object has no attribute append in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/str-object-has-no-attribute-append/m-p/235632#M18330</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am trying to run an array where it loops through my "Cont_Buff" layer selects the first record, then selects all the culverts from the "Culvert_subset" layer that fall within that first record. Then takes the GWP value from the "Cont_Buff" layer and applies it to the WP field for all the selected culverts in the "Culvert_subset" layer. Once it has done this for the first record loop back and do the same for the second record in the "Cont_Buff" layer and so on. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However I have not been able to make it run past the loop because I am getting an 'str object has no attibute error'. My OBJECTID type is not string it is Long.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I've included the entire code block.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;rows = arcpy.SearchCursor("Cont_Buff")
row = rows.next()

CUL_rows = arcpy.UpdateCursor("Culvert_subset")
CUL_row = rows.next()

while row:
&amp;nbsp;&amp;nbsp;&amp;nbsp; a = row.OBJECTID
&amp;nbsp;&amp;nbsp;&amp;nbsp; "OBJECTIDS".append(a)
&amp;nbsp;&amp;nbsp;&amp;nbsp; row = rows.next()

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Set Count equal to the length of the array created in the while loop
&amp;nbsp;&amp;nbsp;&amp;nbsp; Count = len("OBJECTID")

#iterate through each individual feature by using a definition query
while Position &amp;lt; Count: 
&amp;nbsp;&amp;nbsp;&amp;nbsp; query = "[OBJECTID] = " + "'" + OBJECTIDs[Position] + "'"
&amp;nbsp;&amp;nbsp;&amp;nbsp; "Cont_BUff".definitionQuery = query

&amp;nbsp;&amp;nbsp;&amp;nbsp; #center on feature
&amp;nbsp;&amp;nbsp;&amp;nbsp; df.panToExtent("Cont_Buff".getSelectedExtent())

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Select all of the Culverts Cells within the active Site Boundary
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management("Culvert_subset","COMPLETELY_WITHIN","Cont_Buff",0,"NEW_SELECTION")

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Set [WP] equal to Cont_Buff[GWP]
&amp;nbsp;&amp;nbsp;&amp;nbsp; hopper = '"' + str(OBJECTIDs[Position]) + '"'
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management("Culvert_subset","WP",hopper,"VB","#")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am not sure if this is even the correct way to do this seeing as how I cant get past the loop. Any suggestions?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 09 Jan 2013 17:31:21 GMT</pubDate>
    <dc:creator>EmilyAgar1</dc:creator>
    <dc:date>2013-01-09T17:31:21Z</dc:date>
    <item>
      <title>str object has no attribute append</title>
      <link>https://community.esri.com/t5/python-questions/str-object-has-no-attribute-append/m-p/235632#M18330</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am trying to run an array where it loops through my "Cont_Buff" layer selects the first record, then selects all the culverts from the "Culvert_subset" layer that fall within that first record. Then takes the GWP value from the "Cont_Buff" layer and applies it to the WP field for all the selected culverts in the "Culvert_subset" layer. Once it has done this for the first record loop back and do the same for the second record in the "Cont_Buff" layer and so on. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However I have not been able to make it run past the loop because I am getting an 'str object has no attibute error'. My OBJECTID type is not string it is Long.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I've included the entire code block.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;rows = arcpy.SearchCursor("Cont_Buff")
row = rows.next()

CUL_rows = arcpy.UpdateCursor("Culvert_subset")
CUL_row = rows.next()

while row:
&amp;nbsp;&amp;nbsp;&amp;nbsp; a = row.OBJECTID
&amp;nbsp;&amp;nbsp;&amp;nbsp; "OBJECTIDS".append(a)
&amp;nbsp;&amp;nbsp;&amp;nbsp; row = rows.next()

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Set Count equal to the length of the array created in the while loop
&amp;nbsp;&amp;nbsp;&amp;nbsp; Count = len("OBJECTID")

#iterate through each individual feature by using a definition query
while Position &amp;lt; Count: 
&amp;nbsp;&amp;nbsp;&amp;nbsp; query = "[OBJECTID] = " + "'" + OBJECTIDs[Position] + "'"
&amp;nbsp;&amp;nbsp;&amp;nbsp; "Cont_BUff".definitionQuery = query

&amp;nbsp;&amp;nbsp;&amp;nbsp; #center on feature
&amp;nbsp;&amp;nbsp;&amp;nbsp; df.panToExtent("Cont_Buff".getSelectedExtent())

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Select all of the Culverts Cells within the active Site Boundary
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management("Culvert_subset","COMPLETELY_WITHIN","Cont_Buff",0,"NEW_SELECTION")

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Set [WP] equal to Cont_Buff[GWP]
&amp;nbsp;&amp;nbsp;&amp;nbsp; hopper = '"' + str(OBJECTIDs[Position]) + '"'
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management("Culvert_subset","WP",hopper,"VB","#")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am not sure if this is even the correct way to do this seeing as how I cant get past the loop. Any suggestions?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Jan 2013 17:31:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/str-object-has-no-attribute-append/m-p/235632#M18330</guid>
      <dc:creator>EmilyAgar1</dc:creator>
      <dc:date>2013-01-09T17:31:21Z</dc:date>
    </item>
    <item>
      <title>Re: str object has no attribute append</title>
      <link>https://community.esri.com/t5/python-questions/str-object-has-no-attribute-append/m-p/235633#M18331</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;...I see that error when 'recycling' variables thinking I am appending to a list var, when in actuality I'm attempting appending to a string.&amp;nbsp; At any rate, the same methods aren't available...check your variables.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This makes no sense:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"OBJECTIDS".append(a)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;At a glance, it looks like you want to append OBJECTIDs to create a list var called 'a' to contain all your OBJECTID values?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am not convinced this is a good idea, but you could do something like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
a = []
while row:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.append(row.OBJECTID)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row = rows.next()

#Set Count equal to the length of the list variable created in the while loop
Count = len(a)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, check your indention - it isn't quite right either.&amp;nbsp; Also, if you need a count, there is a Get Count tool in Data Management....I think there is a property get from a Describe object too, but it'll suffice to say iterating the records with a cursor is not necessary.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:53:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/str-object-has-no-attribute-append/m-p/235633#M18331</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2021-12-11T11:53:14Z</dc:date>
    </item>
  </channel>
</rss>

