<?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: Problem using Arcpy Update Cursor in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/problem-using-arcpy-update-cursor/m-p/222976#M17237</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I don't believe you will be able to pass a variable for a Update/Search/Insert Cursor.&amp;nbsp; When you specify 'row.fname', the cursor looks for a field called 'fname', even if 'fname' was defined as a variable before hand.&amp;nbsp; The cursor cannot distinguish this.&amp;nbsp; I would recommend using the Field Calculator.&amp;nbsp; You can pass a variable with this function.&amp;nbsp; Ex:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;outshp = "Test.shp"

fname = "id"
isyear = 1

arcpy.CalculateField_management(outshp, fname, isyear)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 10:51:06 GMT</pubDate>
    <dc:creator>JakeSkinner</dc:creator>
    <dc:date>2021-12-11T10:51:06Z</dc:date>
    <item>
      <title>Problem using Arcpy Update Cursor</title>
      <link>https://community.esri.com/t5/python-questions/problem-using-arcpy-update-cursor/m-p/222973#M17234</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi all,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm trying to loop through all the rows of a shapefile field and update the row values, and can't get the Arcpy Update Cursor to work properly. My script crashes when I try to pass the new value that I want to update the row object with. I've tried passing the value as an integer and a string (the field I'm trying to update is an integer type), and I've tried using the row.setValue method as well. Below is my code for creating and using the cursor (code would be properly indented in PyScriptor). If anyone can tell me what I'm doing wrong I would really appreciate it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;rows = arcpy.UpdateCursor(outshp,"","",fname,"")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for row in rows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; isyear = 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.fname = isyear&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;del row&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; del rows&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks in advance!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Billy&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Dec 2011 21:03:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-using-arcpy-update-cursor/m-p/222973#M17234</guid>
      <dc:creator>BillyArmstrong</dc:creator>
      <dc:date>2011-12-28T21:03:10Z</dc:date>
    </item>
    <item>
      <title>Re: Problem using Arcpy Update Cursor</title>
      <link>https://community.esri.com/t5/python-questions/problem-using-arcpy-update-cursor/m-p/222974#M17235</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Billy,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You will just need to wrap the field name in quotations within the UpdateCursor function.&amp;nbsp; Ex:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;rows = arcpy.UpdateCursor(outshp,"", "", &lt;STRONG&gt;"fname"&lt;/STRONG&gt;, "")
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; isyear = 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; row.fname = isyear
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)

del row
del rows&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, you can preserve the indentation of your code by using the code tags (# symbol).&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:51:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-using-arcpy-update-cursor/m-p/222974#M17235</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-11T10:51:03Z</dc:date>
    </item>
    <item>
      <title>Re: Problem using Arcpy Update Cursor</title>
      <link>https://community.esri.com/t5/python-questions/problem-using-arcpy-update-cursor/m-p/222975#M17236</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Jake,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The field name is actually a variable from previous geoprocessing operations, and was used to name a newly created field. If I manually enter the specific field in quotes the Update Cursor works fine. I'm trying to pass the variable so it can loop through a series of shapefiles which get updated with a unique field names. The Update Cursor seems to accept the variable name, however the row.&amp;lt;name&amp;gt; method crashes every time with it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Billy&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Dec 2011 15:22:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-using-arcpy-update-cursor/m-p/222975#M17236</guid>
      <dc:creator>BillyArmstrong</dc:creator>
      <dc:date>2011-12-29T15:22:17Z</dc:date>
    </item>
    <item>
      <title>Re: Problem using Arcpy Update Cursor</title>
      <link>https://community.esri.com/t5/python-questions/problem-using-arcpy-update-cursor/m-p/222976#M17237</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I don't believe you will be able to pass a variable for a Update/Search/Insert Cursor.&amp;nbsp; When you specify 'row.fname', the cursor looks for a field called 'fname', even if 'fname' was defined as a variable before hand.&amp;nbsp; The cursor cannot distinguish this.&amp;nbsp; I would recommend using the Field Calculator.&amp;nbsp; You can pass a variable with this function.&amp;nbsp; Ex:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;outshp = "Test.shp"

fname = "id"
isyear = 1

arcpy.CalculateField_management(outshp, fname, isyear)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:51:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-using-arcpy-update-cursor/m-p/222976#M17237</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-11T10:51:06Z</dc:date>
    </item>
    <item>
      <title>Re: Problem using Arcpy Update Cursor</title>
      <link>https://community.esri.com/t5/python-questions/problem-using-arcpy-update-cursor/m-p/222977#M17238</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Another way you could try it would be like the following, since your code succeeds with manual field naming versus derived:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;rows = arcpy.UpdateCursor(outshp,"","",&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ---&amp;gt; "%s" %(fname,) &amp;lt;-----&amp;nbsp;&amp;nbsp;&amp;nbsp; ,"")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Dec 2011 19:26:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-using-arcpy-update-cursor/m-p/222977#M17238</guid>
      <dc:creator>RobertJones6</dc:creator>
      <dc:date>2011-12-29T19:26:18Z</dc:date>
    </item>
    <item>
      <title>Re: Problem using Arcpy Update Cursor</title>
      <link>https://community.esri.com/t5/python-questions/problem-using-arcpy-update-cursor/m-p/222978#M17239</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the replies. I ended up using the Field Calculator and it worked great.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Billy&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Jan 2012 13:46:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-using-arcpy-update-cursor/m-p/222978#M17239</guid>
      <dc:creator>BillyArmstrong</dc:creator>
      <dc:date>2012-01-04T13:46:18Z</dc:date>
    </item>
  </channel>
</rss>

