<?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: ArcPy script to search, get value, compare to field names and sum field values in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/arcpy-script-to-search-get-value-compare-to-field/m-p/600504#M19937</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Xander, thank you so much. I knew I was missing the ability to get the values from the cursor, just didn't know how to go about it.&lt;/P&gt;&lt;P&gt;I have run the code on data. The intended field (TotRegFlows) is being updated but I am not sure how the figure is calculated. Each row (or Ward) should have a unique total. By running the code, all rows with the same RegID_6k99 value has the same. I have calculated the correct totals manually for two RegID_6k99 values. I have attached a screendump of one example where RegID_6k99 = 4. In the example there are 3 wards with a region ID of 4. the FLABELs of these wards are F95XX01, F95XX10, F95XX11. Correct flow totals are shown in the attached screendump.&lt;/P&gt;&lt;P&gt;The values from running the code for these three rows or wards are all &lt;STRONG&gt;962. &lt;/STRONG&gt;I can't spot where this value is coming from.&lt;/P&gt;&lt;P&gt;Do you think the error could be related to the sorting of fields? Should&amp;nbsp; include a print somewhere along the way to check expected values?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="ExampleRegID_6k99_RegID4.jpg" class="jive-image image-1" src="https://community.esri.com/legacyfs/online/2676_ExampleRegID_6k99_RegID4.jpg" style="height: auto;" /&gt;&lt;/P&gt;&lt;P&gt;Xander, thanks for your help, I really appreciate it&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lorraine&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 29 Jul 2014 13:15:50 GMT</pubDate>
    <dc:creator>LorraineBarry</dc:creator>
    <dc:date>2014-07-29T13:15:50Z</dc:date>
    <item>
      <title>ArcPy script to search, get value, compare to field names and sum field values</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/arcpy-script-to-search-get-value-compare-to-field/m-p/600497#M19930</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am relatively new to Python (although experienced in GIS). I am working with a feature class which was joined by a matrix of flow data for areas. Each area has unique string label. I have run a seperate script to cluster the areas into regions and have attached the region number to the feature class. Each region has between 5-19 areas. I have attached a screendump of the feature class&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am looking to write a script to loop through each of the region ID numbers ("RegID_6k99"), select all of the areas which have that number, for these areas look at the area label and sum the cell values for the row based only where field names are the same as those belonging to the region.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have written the code as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt; import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt; fieldlist = arcpy.ListFields("C:/Temp/lorraine/NIData.gdb/fc_f6000_in99Matx")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt; for field in fieldlist:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; print field.name&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt;fc = "C:/Temp/lorraine/NIData.gdb/fc_f6000_in99Matx"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt; regfield = "RegID_6k99"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt; cursor = arcpy.SearchCursor(fc)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt; for row in cursor:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; print(row.getValue(regfield))&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; &amp;gt;&amp;gt;&amp;gt; for row in cursor:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; if row.getValue(regfield)=="1":&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; row.getValue(LABEL)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; print row.getValue(LABEL)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a search cursor to get a certain value. So I need to increment this upwards and I need to link the selection to the field name (fieldlist) and sum the values in those cells to a new column.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Help! I'm stuck. Don't know how to implement these last stages. Any advice gratefully accepted. Lorraine&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jun 2014 11:23:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/arcpy-script-to-search-get-value-compare-to-field/m-p/600497#M19930</guid>
      <dc:creator>LorraineBarry</dc:creator>
      <dc:date>2014-06-19T11:23:37Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy script to search, get value, compare to field names and sum field values</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/arcpy-script-to-search-get-value-compare-to-field/m-p/600498#M19931</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If I understand this correctly, you want something like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;result = [row[0] for row in arcpy.da.SearchCursor(
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; outFC,
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; ("RegID_6k99"))]
unique = set(result)

lengthDict = {}

for uni in unique:
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; where = "\"RegID_6k99\" = '%s'" % (uni)

&amp;nbsp;&amp;nbsp;&amp;nbsp; lengths = [row[0] for row in arcpy.da.SearchCursor(
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; fc,
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; ("Shape_Length"),
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; where)]
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; lengthDict[uni] = sum(lengths)

for each in lengthDict.keys():
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "%s: %s" % (each, lengthDict[each])&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This should print out the total lengths for each RegID_6k99 value.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;&amp;lt; no warranties expressed or implied &amp;gt;&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-style:italic;"&gt;note: use the '#' button to add code tags to your post&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:45:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/arcpy-script-to-search-get-value-compare-to-field/m-p/600498#M19931</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2021-12-12T01:45:22Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy script to search, get value, compare to field names and sum field values</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/arcpy-script-to-search-get-value-compare-to-field/m-p/600499#M19932</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;IMG alt="SearchCursor_Task.jpg" class="jive-image image-2" src="https://community.esri.com/legacyfs/online/1670_SearchCursor_Task.jpg" style="width: 620px; height: 158px;" /&gt;&lt;/P&gt;&lt;P&gt;Many thanks Mark for your reply. This has been really useful. I have been working through it and have tried to modify it slightly. I have run into some errors (see attached jpg) and I don't think it does exactly what I want it to do. I don't think I explained the task very well initially. So I will need to modify the code further but its definitely (thanks to your help) going in the right direction.&lt;/P&gt;&lt;P&gt;I have attached a txt file explaining what I am trying to do. Any other suggestions greatly accepted. I have been working on this for many days - nearly pulling my hair out. The task is critical to proceed. The number of records does not change but the assigned region value for each record can have an exponential amount of permutations which I need to test. Therefore automation is crucial.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks again&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lorraine&lt;IMG alt="Script.jpg" class="jive-image image-1" src="https://community.esri.com/legacyfs/online/1657_Script.jpg" style="width: 620px; height: 658px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Jul 2014 11:32:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/arcpy-script-to-search-get-value-compare-to-field/m-p/600499#M19932</guid>
      <dc:creator>LorraineBarry</dc:creator>
      <dc:date>2014-07-08T11:32:01Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy script to search, get value, compare to field names and sum field values</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/arcpy-script-to-search-get-value-compare-to-field/m-p/600500#M19933</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've modified the script to include looking at the field name but I need to sort out the if else statement at the end.&lt;/P&gt;&lt;P&gt;Help please!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any comments greatly appreciated&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lorraine&lt;IMG alt="v4.jpg" class="jive-image image-1" src="https://community.esri.com/legacyfs/online/1745_v4.jpg" style="width: 620px; height: 426px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Jul 2014 22:13:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/arcpy-script-to-search-get-value-compare-to-field/m-p/600500#M19933</guid>
      <dc:creator>LorraineBarry</dc:creator>
      <dc:date>2014-07-09T22:13:16Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy script to search, get value, compare to field names and sum field values</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/arcpy-script-to-search-get-value-compare-to-field/m-p/600501#M19934</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Lorraine,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please have a look at the code below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14065084381968616" jivemacro_uid="_14065084381968616" modifiedtitle="true"&gt;
&lt;P&gt;import arcpy&lt;/P&gt;
&lt;P&gt;fc = "C:/Temp/lorraine/NIData.gdb/fc_f6000_in99Matx"&lt;/P&gt;
&lt;P&gt;fld_id = "RegID_6k99"&lt;/P&gt;
&lt;P&gt;fld_label = "FLABEL"&lt;/P&gt;
&lt;P&gt;fld_flows = "RegIntFlows"&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# create a unique list of all the FLABEL values&lt;/P&gt;
&lt;P&gt;lst_labels = list(set([row[0] for row in arcpy.da.SearchCursor(fc, (fld_label))]))&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Create the list of fields to be used in the SearchCursor&lt;/P&gt;
&lt;P&gt;flds = [fld_id, fld_label]&lt;/P&gt;
&lt;P&gt;flds.extent(lst_labels)&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# create list of all fields&lt;/P&gt;
&lt;P&gt;flds_all = arcpy.ListFields(fc)&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# make sure that the relevant fields for the SearchCursor exist in fc&lt;/P&gt;
&lt;P&gt;flds = list(set(flds) &amp;amp; set(flds_all))&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# loop through data and fill the result dictionary&lt;/P&gt;
&lt;P&gt;dct_res = {}&lt;/P&gt;
&lt;P&gt;with arcpy.da.SearchCursor(fc, flds) as curs:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in curs:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uni_id = row[flds.index(fld_id)]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lbl = row[flds.index(fld_label)]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lbl in flds:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; val = row[flds.index(lbl)]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if uni_id in dct_res:&lt;/P&gt;
&lt;P&gt;&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; dct_rec[uni_id] += val&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/P&gt;
&lt;P&gt;&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; dct_rec[uni_id] = val&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # lbl in field FLABEL does not exist as field&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pass&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# now update the values with an update cursor and the result dictionary&lt;/P&gt;
&lt;P&gt;flds = (fld_id, fld_flows)&lt;/P&gt;
&lt;P&gt;with arcpy.da.UpdateCursor(fc, flds) as curs:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in curs:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[1] = dct_res[row[0]]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.updateRow(row)&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;First of all I have not tested the code, so this might not work at all. If you are willing to attach a part of your data to this thread, I could test the code and tweak it where necessary...&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'll try to explain what I intent to do in the code:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;on line 8, a unique list of all the values in the field FLABEL is created. This will be used later on to define the fields for the search cursor&lt;/LI&gt;&lt;LI&gt;on line 11 and 12, the actual list of fields created (all the FLABEL values and the RegID_6k99 field and the FLABEL field)&lt;/LI&gt;&lt;LI&gt;on line 15 a list of fields is created (all fields in the featureclass)&lt;/LI&gt;&lt;LI&gt;on line 18 the list of fields (from line 12) is tested against the available fields in the featureclass&lt;/LI&gt;&lt;LI&gt;on line 22 a search cursor is started to read for each record the RegID_6k99 and the FLABEL (please note the I'm using &lt;EM&gt;flds.index(fieldname)&lt;/EM&gt; to determine the index number to access the correct field in the row tuple)&lt;/LI&gt;&lt;LI&gt;on line 26, there is a test to see if the FLABEL value actually exists as fieldname in the fc&lt;/LI&gt;&lt;LI&gt;on line 27, the value is read for the FLABEL value field&lt;/LI&gt;&lt;LI&gt;lines 28 - 31 add the value to the result dictionary. The dictionary will contain each RegID_6k99 value and the sum of the values&lt;/LI&gt;&lt;LI&gt;on line 38 a update cursor is defined which will update the RegIntFlows value of the cursor assuming the field RegIntFlows already exists&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope this makes sense to you and that the code actually runs. If not, please let me know and I see what I can do.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xander&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jul 2014 00:59:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/arcpy-script-to-search-get-value-compare-to-field/m-p/600501#M19934</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2014-07-28T00:59:33Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy script to search, get value, compare to field names and sum field values</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/arcpy-script-to-search-get-value-compare-to-field/m-p/600502#M19935</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;@XanderBakker, thank you so much for taking the time and effort to look at this, this is really helpful. I was completely stuck with it. You are brilliant. The code sounds as if it will do exactly as I want it to do.&lt;/P&gt;&lt;P&gt;I've tried running the code but I get an error with the list and update cursor. Any ideas?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="NewCode_Error2.jpg" class="jive-image image-1" src="https://community.esri.com/legacyfs/online/2661_NewCode_Error2.jpg" style="width: 620px; height: 704px;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have zipped up feature class and attached it here. If you could take a look that would be great.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks Xander&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lorraine&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jul 2014 14:16:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/arcpy-script-to-search-get-value-compare-to-field/m-p/600502#M19935</guid>
      <dc:creator>LorraineBarry</dc:creator>
      <dc:date>2014-07-28T14:16:47Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy script to search, get value, compare to field names and sum field values</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/arcpy-script-to-search-get-value-compare-to-field/m-p/600503#M19936</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Lorraine,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for sending the dataset. This way I could test the code and noticed that I had quite a number of errors in the script. &lt;/P&gt;&lt;P&gt;Please observe the corrected code that "did something" (you should verify if the values correspond to what you expected).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14065633757624537 jive_text_macro" jivemacro_uid="_14065633757624537"&gt;
&lt;P&gt;import arcpy&lt;/P&gt;
&lt;P&gt;# fc = "D:/Xander/tmp/NIData.gdb/test_copy"&lt;/P&gt;
&lt;P&gt;fc = "C:/Temp/lorraine/NIData.gdb/fc_f6000_in99Matx"&lt;/P&gt;
&lt;P&gt;fld_id = "RegID_6k99"&lt;/P&gt;
&lt;P&gt;fld_label = "FLABEL"&lt;/P&gt;
&lt;P&gt;fld_flows = "RegIntFlows"&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# create a unique list of all the FLABEL values&lt;/P&gt;
&lt;P&gt;lst_labels = list(set([row[0] for row in arcpy.da.SearchCursor(fc, (fld_label))]))&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Create the list of fields to be used in the SearchCursor&lt;/P&gt;
&lt;P&gt;flds = [fld_id, fld_label]&lt;/P&gt;
&lt;P&gt;flds.extend(lst_labels)&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# create list of all fields&lt;/P&gt;
&lt;P&gt;flds_all = [fld.name for fld in arcpy.ListFields(fc)]&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# make sure that the relevant fields for the SearchCursor exist in fc&lt;/P&gt;
&lt;P&gt;flds = list(set(flds) &amp;amp; set(flds_all))&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# loop through data and fill the result dictionary&lt;/P&gt;
&lt;P&gt;dct_res = {}&lt;/P&gt;
&lt;P&gt;with arcpy.da.SearchCursor(fc, flds) as curs:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in curs:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uni_id = row[flds.index(fld_id)]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lbl = row[flds.index(fld_label)]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lbl in flds:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; val = row[flds.index(lbl)]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if uni_id in dct_res:&lt;/P&gt;
&lt;P&gt;&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; dct_res[uni_id] += val&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/P&gt;
&lt;P&gt;&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; dct_res[uni_id] = val&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # lbl in field FLABEL does not exist as field&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pass&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# now update the values with an update cursor and the result dictionary&lt;/P&gt;
&lt;P&gt;flds = (fld_id, fld_flows)&lt;/P&gt;
&lt;P&gt;with arcpy.da.UpdateCursor(fc, flds) as curs:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in curs:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[1] = dct_res[row[0]]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; curs.updateRow(row)&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Some of the errors in the code where:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;line 13 I write "flds.exten&lt;STRONG&gt;t&lt;/STRONG&gt;()" when this should be "flds.exten&lt;STRONG&gt;d&lt;/STRONG&gt;()"&lt;/LI&gt;&lt;LI&gt;line 16 has been changed. The ListFields returns field objects and not the field names. line changed to use a List Comprehension to generate the list of field names&lt;/LI&gt;&lt;LI&gt;Line 30 and 32 referred to a variable called "dct_re&lt;STRONG&gt;c&lt;/STRONG&gt;" in stead of "dct_re&lt;STRONG&gt;s&lt;/STRONG&gt;"&lt;/LI&gt;&lt;LI&gt;Line 42 tried to do an updateRow on the row object when this should be called on the curs object&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;At least I learned a thing that I shouldn't try to do these kind of things without a dataset... &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this works for you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xander&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jul 2014 16:07:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/arcpy-script-to-search-get-value-compare-to-field/m-p/600503#M19936</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2014-07-28T16:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy script to search, get value, compare to field names and sum field values</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/arcpy-script-to-search-get-value-compare-to-field/m-p/600504#M19937</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Xander, thank you so much. I knew I was missing the ability to get the values from the cursor, just didn't know how to go about it.&lt;/P&gt;&lt;P&gt;I have run the code on data. The intended field (TotRegFlows) is being updated but I am not sure how the figure is calculated. Each row (or Ward) should have a unique total. By running the code, all rows with the same RegID_6k99 value has the same. I have calculated the correct totals manually for two RegID_6k99 values. I have attached a screendump of one example where RegID_6k99 = 4. In the example there are 3 wards with a region ID of 4. the FLABELs of these wards are F95XX01, F95XX10, F95XX11. Correct flow totals are shown in the attached screendump.&lt;/P&gt;&lt;P&gt;The values from running the code for these three rows or wards are all &lt;STRONG&gt;962. &lt;/STRONG&gt;I can't spot where this value is coming from.&lt;/P&gt;&lt;P&gt;Do you think the error could be related to the sorting of fields? Should&amp;nbsp; include a print somewhere along the way to check expected values?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="ExampleRegID_6k99_RegID4.jpg" class="jive-image image-1" src="https://community.esri.com/legacyfs/online/2676_ExampleRegID_6k99_RegID4.jpg" style="height: auto;" /&gt;&lt;/P&gt;&lt;P&gt;Xander, thanks for your help, I really appreciate it&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lorraine&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jul 2014 13:15:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/arcpy-script-to-search-get-value-compare-to-field/m-p/600504#M19937</guid>
      <dc:creator>LorraineBarry</dc:creator>
      <dc:date>2014-07-29T13:15:50Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy script to search, get value, compare to field names and sum field values</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/arcpy-script-to-search-get-value-compare-to-field/m-p/600505#M19938</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Lorraine,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I understood is that the code should sum the values for all records for a RegID_6k99. That's why the result is higher than you expected. Based on what you are showing, it seems that the calculation should be affected for each row. This means that there is no need to have both the Search cursor and the Update cursor. A single Update cursor will do. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Before I start with the changes in the code, let me get some things clear:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;in the image I suppose that cells A4 and D1 should be "&lt;STRONG&gt;F95XX1&lt;SPAN style="color: #2873ee;"&gt;1&lt;/SPAN&gt;&lt;/STRONG&gt;" in stead of "&lt;STRONG&gt;F92XX1&lt;SPAN style="color: #e23d39;"&gt;0&lt;/SPAN&gt;&lt;/STRONG&gt;".&lt;/LI&gt;&lt;LI&gt;the example show all the records (3) for RegID_6k99 = 4&lt;/LI&gt;&lt;LI&gt;the FLABEL field for those 3 records contains the values F95XX01, F95XX10 and F95XX11&lt;/LI&gt;&lt;LI&gt;for each record those fields (F95XX01, F95XX10 and F95XX11) should be summed (in case RegID_6k99 = 4)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If this is the case we will need to create an initial dictionary that stores the 1:n relation of RegID_6k99 and FLABEL. In the update cursor we will need to read this dictionary to determine which fields to sum.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If this is what you are looking for, let me know and I'll dive into that.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xander&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jul 2014 14:19:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/arcpy-script-to-search-get-value-compare-to-field/m-p/600505#M19938</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2014-07-29T14:19:46Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy script to search, get value, compare to field names and sum field values</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/arcpy-script-to-search-get-value-compare-to-field/m-p/600506#M19939</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Lorraine,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try this code, it creates the same value you are expecting:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14066451505444209 jive_text_macro" jivemacro_uid="_14066451505444209"&gt;
&lt;P&gt;import arcpy&lt;/P&gt;
&lt;P&gt;# fc = "D:/Xander/tmp/NIData.gdb/test_copy"&lt;/P&gt;
&lt;P&gt;fc = "C:/Temp/lorraine/NIData.gdb/fc_f6000_in99Matx"&lt;/P&gt;
&lt;P&gt;fld_id = "RegID_6k99"&lt;/P&gt;
&lt;P&gt;fld_label = "FLABEL"&lt;/P&gt;
&lt;P&gt;fld_flows = "RegIntFlows"&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# create a unique list of all the FLABEL values&lt;/P&gt;
&lt;P&gt;lst_labels = list(set([row[0] for row in arcpy.da.SearchCursor(fc, (fld_label))]))&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Create the list of fields to be used in the SearchCursor&lt;/P&gt;
&lt;P&gt;flds = [fld_id, fld_label]&lt;/P&gt;
&lt;P&gt;flds.extend(lst_labels)&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# create list of all fields&lt;/P&gt;
&lt;P&gt;flds_all = [fld.name for fld in arcpy.ListFields(fc)]&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# make sure that the relevant fields for the SearchCursor exist in fc&lt;/P&gt;
&lt;P&gt;flds = list(set(flds) &amp;amp; set(flds_all))&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# create a dictionary with for each RegID_6k99 a list of corresponding FLABEL fields&lt;/P&gt;
&lt;P&gt;dct_ref ={}&lt;/P&gt;
&lt;P&gt;flds2 = (fld_id, fld_label)&lt;/P&gt;
&lt;P&gt;with arcpy.da.SearchCursor(fc, flds2) as curs:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in curs:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uni_id = row[0]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lbl = row[1]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if uni_id in dct_ref:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lst_lbls = dct_ref[uni_id]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not lbl in lst_lbls:&lt;/P&gt;
&lt;P&gt;&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; lst_lbls.append(lbl)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lst_lbls = [lbl]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dct_ref[uni_id] = lst_lbls&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# loop through data and fill the result dictionary&lt;/P&gt;
&lt;P&gt;flds.append(fld_flows)&lt;/P&gt;
&lt;P&gt;with arcpy.da.UpdateCursor(fc, flds) as curs:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in curs:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uni_id = row[flds.index(fld_id)]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if uni_id in dct_ref:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lst_lbls = dct_ref[uni_id]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; val = 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for lbl in lst_lbls:&lt;/P&gt;
&lt;P&gt;&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 lbl in flds:&lt;/P&gt;
&lt;P&gt;&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; val += row[flds.index(lbl)]&lt;/P&gt;
&lt;P&gt;&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:&lt;/P&gt;
&lt;P&gt;&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; print " - lbl {0} in field FLABEL for RegID_6k99 = {1} does not exist as field".format(lbl, uni_id)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[flds.index(fld_flows)] = val&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; curs.updateRow(row)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "key uni_id {0} not found in dct_ref".format(uni_id)&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What has changed is this:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;lines 22 - 34 creates a dictionary with unique FLABELS per RegID_6k99&lt;/LI&gt;&lt;LI&gt;lines 37 - 52 the search cursor and update cursor have been replaced by a single update cursor.&lt;/LI&gt;&lt;LI&gt;line 42 reads the list of FLABELS for the current RegID_6k99&lt;/LI&gt;&lt;LI&gt;lines 44 - 46 sums the relevant values&lt;/LI&gt;&lt;LI&gt;line 49 stores the value in the flow field&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xander&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jul 2014 14:49:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/arcpy-script-to-search-get-value-compare-to-field/m-p/600506#M19939</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2014-07-29T14:49:04Z</dc:date>
    </item>
  </channel>
</rss>

