<?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 searchcursor only takes first value in field in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/searchcursor-only-takes-first-value-in-field/m-p/577175#M45269</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My script ArcGIS 10.2 is using the searchcursor to read the mLanduse feature class to return the value in lField, but it is only returning the first value in lField to populate the sField in mSoils. Is my cursor2.updateRow in the wrong spot?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&lt;CODE&gt;&lt;SPAN class="com"&gt;# Create a cursor on a feature class&lt;/SPAN&gt;&lt;/CODE&gt;
with arcpy.da.SearchCursor(&lt;CODE&gt;&lt;SPAN class="pln"&gt;mLanduse&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; lField&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;&lt;/SPAN&gt;&lt;/CODE&gt;) as cursor:

&lt;CODE&gt;&lt;SPAN class="com"&gt;# Loop through the rows and update the blank sField values in mSoils &lt;/SPAN&gt;&lt;SPAN class="pln"&gt;&lt;/SPAN&gt;&lt;SPAN class="com"&gt;with the lField values from mLanduse&lt;/SPAN&gt;&lt;/CODE&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.UpdateCursor(&lt;CODE&gt;&lt;SPAN class="pln"&gt;mSoils&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; sField&lt;/SPAN&gt;&lt;/CODE&gt;) as cursor2:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row2 in cursor2:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if row2[0] == ' ':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row2[0] = row[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row2[0] = ' '
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor2.updateRow(row2)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 00:49:47 GMT</pubDate>
    <dc:creator>MarkWisniewski</dc:creator>
    <dc:date>2021-12-12T00:49:47Z</dc:date>
    <item>
      <title>searchcursor only takes first value in field</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-only-takes-first-value-in-field/m-p/577175#M45269</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My script ArcGIS 10.2 is using the searchcursor to read the mLanduse feature class to return the value in lField, but it is only returning the first value in lField to populate the sField in mSoils. Is my cursor2.updateRow in the wrong spot?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&lt;CODE&gt;&lt;SPAN class="com"&gt;# Create a cursor on a feature class&lt;/SPAN&gt;&lt;/CODE&gt;
with arcpy.da.SearchCursor(&lt;CODE&gt;&lt;SPAN class="pln"&gt;mLanduse&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; lField&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;&lt;/SPAN&gt;&lt;/CODE&gt;) as cursor:

&lt;CODE&gt;&lt;SPAN class="com"&gt;# Loop through the rows and update the blank sField values in mSoils &lt;/SPAN&gt;&lt;SPAN class="pln"&gt;&lt;/SPAN&gt;&lt;SPAN class="com"&gt;with the lField values from mLanduse&lt;/SPAN&gt;&lt;/CODE&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.UpdateCursor(&lt;CODE&gt;&lt;SPAN class="pln"&gt;mSoils&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;,&lt;/SPAN&gt;&lt;SPAN class="pln"&gt; sField&lt;/SPAN&gt;&lt;/CODE&gt;) as cursor2:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row2 in cursor2:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if row2[0] == ' ':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row2[0] = row[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row2[0] = ' '
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor2.updateRow(row2)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:49:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-only-takes-first-value-in-field/m-p/577175#M45269</guid>
      <dc:creator>MarkWisniewski</dc:creator>
      <dc:date>2021-12-12T00:49:47Z</dc:date>
    </item>
    <item>
      <title>Re: searchcursor only takes first value in field</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-only-takes-first-value-in-field/m-p/577176#M45270</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ernst,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I believe your workflow may be incorrect.&amp;nbsp; Your above code will find the first lField value in the mLanduse feature class, then update every row in the mSoils feature class where the sField is blank.&amp;nbsp; It will then find the second row in mLanduse and update every row in mSoils where the SField is blank.&amp;nbsp; It will continue to do this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a related field in mLanduse and mSoils where you can perform a join, select the blank rows, and then use the field calculator to update these rows?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If possible, would you be able to provide a small sample of you data?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Apr 2015 11:44:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-only-takes-first-value-in-field/m-p/577176#M45270</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2015-04-30T11:44:39Z</dc:date>
    </item>
    <item>
      <title>Re: searchcursor only takes first value in field</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-only-takes-first-value-in-field/m-p/577177#M45271</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Jake, thanks for explaining this. There is no related table. My output is doing the following as stated by yourself;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"Your above code will find the first lField value in the mLanduse feature class, then update every row in the mSoils feature class where the sField is blank".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Okay, how do I change my script so it finds the first lField value in the mLanduse feature class then updates ONLY the rows according to the SelectByLocation in the mSoils feature class where the sField is Blank?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And then; "It will then find the second row in mLanduse and update every row in mSoils where the SField is blank".&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Apr 2015 12:13:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-only-takes-first-value-in-field/m-p/577177#M45271</guid>
      <dc:creator>MarkWisniewski</dc:creator>
      <dc:date>2015-04-30T12:13:18Z</dc:date>
    </item>
    <item>
      <title>Re: searchcursor only takes first value in field</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-only-takes-first-value-in-field/m-p/577178#M45272</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Attached is some data you can test with.&amp;nbsp; The below script will update the 'Soil' field in the 'Soil' feature class based on the 'SoilType' field within the 'LandUse' feature class.&amp;nbsp; The code performs a spatial join, joins the output from this tool to the Soil feature class, selects all empty values in the Soil field and then updates these values using the Calculate Field tool.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
from arcpy import env
env.overwriteOutput = 1
env.workspace = r"C:\temp\python\test.gdb"

mLanduse = "LandUse"
mSoils = "Soil"

arcpy.SpatialJoin_analysis(mSoils, mLanduse, r"IN_MEMORY\join")

arcpy.MakeFeatureLayer_management(mSoils, "soilsLyr")
arcpy.MakeFeatureLayer_management(r"IN_MEMORY\join", "joinLyr")

arcpy.AddJoin_management("soilsLyr", "OBJECTID", "joinLyr", "TARGET_FID")
arcpy.SelectLayerByAttribute_management("soilsLyr", "NEW_SELECTION", "Soil.Soil = ''")

arcpy.CalculateField_management("soilsLyr", "Soil.Soil", "[join.SoilType]", "VB")
print 'finished'&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:49:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-only-takes-first-value-in-field/m-p/577178#M45272</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-12T00:49:50Z</dc:date>
    </item>
    <item>
      <title>Re: searchcursor only takes first value in field</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-only-takes-first-value-in-field/m-p/577179#M45273</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I understand correctly what you are trying to do, and using as much of your original code as possible, I roughed out the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;with arcpy.da.SearchCursor(mLanduse, ["SHAPE@", lField]) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mSoils_Layer, "WITHIN", row[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.UpdateCursor(mSoils_Layer, sField) as cursor2:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row2 in cursors2:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if row2[0] == '':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row2[0] = row[1]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor2.updateRow(row2)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If this works, I can explain how your original code had some parts out of order.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:49:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-only-takes-first-value-in-field/m-p/577179#M45273</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-12T00:49:53Z</dc:date>
    </item>
    <item>
      <title>Re: searchcursor only takes first value in field</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-only-takes-first-value-in-field/m-p/577180#M45274</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Joshua,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your effort, but no luck. The script doesn't like the SelectByLocation in the SearchCursor.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Apr 2015 23:37:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-only-takes-first-value-in-field/m-p/577180#M45274</guid>
      <dc:creator>MarkWisniewski</dc:creator>
      <dc:date>2015-04-30T23:37:57Z</dc:date>
    </item>
    <item>
      <title>Re: searchcursor only takes first value in field</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-only-takes-first-value-in-field/m-p/577181#M45275</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You really do need to do the spatial join, of course you can make it more efficient by doing a Select Layer By Location before you do your overlay (as Mr. Bixby suggests).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 May 2015 01:11:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-only-takes-first-value-in-field/m-p/577181#M45275</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2015-05-01T01:11:24Z</dc:date>
    </item>
    <item>
      <title>Re: searchcursor only takes first value in field</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-only-takes-first-value-in-field/m-p/577182#M45276</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Curios, what is the specific error message?&amp;nbsp; (&lt;EM&gt;By the way, it is a good practice to include specific error messages instead of general comments like "doesn't like.").&lt;/EM&gt;&amp;nbsp; It could be I just gave some incorrect syntax or names since I was interpreting your original code snippet.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 May 2015 05:01:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-only-takes-first-value-in-field/m-p/577182#M45276</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2015-05-01T05:01:58Z</dc:date>
    </item>
    <item>
      <title>Re: searchcursor only takes first value in field</title>
      <link>https://community.esri.com/t5/python-questions/searchcursor-only-takes-first-value-in-field/m-p/577183#M45277</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Joshua,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm not really sure to be honest. I do not do the printing side of things in IDLE (bad practice?). I have the script open in ArcGIS, run it, if it works great, if not, I do more research and ask questions online and update script through IDLE and repeat process.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I'm trying to work out why my loop isn't stopping.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 May 2015 05:18:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searchcursor-only-takes-first-value-in-field/m-p/577183#M45277</guid>
      <dc:creator>MarkWisniewski</dc:creator>
      <dc:date>2015-05-01T05:18:09Z</dc:date>
    </item>
  </channel>
</rss>

