<?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: Basic attribute transfer in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/basic-attribute-transfer/m-p/1151495#M63992</link>
    <description>&lt;P&gt;If I wanted to update another field (3rd) from that same table how would I do that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;sourceFC = "C:/Temp/Temp.gdb/Table1"
where_clause = "MU LIKE '%TZ%'"
search_feats ={f[0]:(f[1:]} for f in arcpy.da.SearchCursor(sourceFC,["OBJECTID",'MU', 'KL'],where_clause)}
#searchVals = set(search_feats)
#print(search_feats)

with arcpy.da.UpdateCursor(sourceFC,["OBJECTID","MU_update", "KL_update"]) as upd_cur:
for upd_row in upd_cur:
    try:
       upd_row[1] = search_feats[upd_row[0]]
       upd_row[2] = search_feats[upd_row[0]][2] ????
       upd_cur.updateRow(upd_row)
    except:
       continue&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 07 Mar 2022 21:56:51 GMT</pubDate>
    <dc:creator>2Quiker</dc:creator>
    <dc:date>2022-03-07T21:56:51Z</dc:date>
    <item>
      <title>Basic attribute transfer</title>
      <link>https://community.esri.com/t5/python-questions/basic-attribute-transfer/m-p/1151435#M63984</link>
      <description>&lt;P&gt;I am trying to transfer attributes within a table from field "MU" to "MU_update" field but I get this error and I think it is because of my were_Clause but I am not 100% sure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"upd_row[1] = search_feats[upd_row[0]]&lt;BR /&gt;KeyError: 1"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

env.workspace = "C:/Temp/PermitTest/PermitsTestData1/Permits.gdb"

sourceFC = "C:/Temp/Temp.gdb/Table1"
where_clause = "MU LIKE '%TZ%'"
search_feats ={f[0]:f[1] for f in arcpy.da.SearchCursor(sourceFC,["OBJECTID",'MU'],where_clause)}
#searchVals = set(search_feats)
#print(search_feats)

with arcpy.da.UpdateCursor(sourceFC,["OBJECTID","MU_update"]) as upd_cur:
    for upd_row in upd_cur:
        upd_row[1] = search_feats[upd_row[0]]
        upd_cur.updateRow(upd_row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Mar 2022 19:13:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/basic-attribute-transfer/m-p/1151435#M63984</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2022-03-07T19:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: Basic attribute transfer</title>
      <link>https://community.esri.com/t5/python-questions/basic-attribute-transfer/m-p/1151439#M63985</link>
      <description>&lt;P&gt;Why not apply a definition query and use the calculate field tool?&lt;/P&gt;</description>
      <pubDate>Mon, 07 Mar 2022 19:32:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/basic-attribute-transfer/m-p/1151439#M63985</guid>
      <dc:creator>TonyContreras_Frisco_TX</dc:creator>
      <dc:date>2022-03-07T19:32:45Z</dc:date>
    </item>
    <item>
      <title>Re: Basic attribute transfer</title>
      <link>https://community.esri.com/t5/python-questions/basic-attribute-transfer/m-p/1151441#M63986</link>
      <description>&lt;P&gt;Your dictionary only contains the OIDs which match your where_clause, but your update cursor is trying all OID keys - the problem being that some OIDs don't exist in your dictionary and throw the error.&lt;/P&gt;&lt;P&gt;You can throw in a try except&lt;/P&gt;&lt;LI-CODE lang="python"&gt;for upd_row in upd_cur:
        try:
            upd_row[1] = search_feats[upd_row[0]]
            upd_cur.updateRow(upd_row)
        except:
            continue&lt;/LI-CODE&gt;&lt;P&gt;but using the same where_clause on the update cursor will probably be much faster.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Mar 2022 19:34:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/basic-attribute-transfer/m-p/1151441#M63986</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2022-03-07T19:34:18Z</dc:date>
    </item>
    <item>
      <title>Re: Basic attribute transfer</title>
      <link>https://community.esri.com/t5/python-questions/basic-attribute-transfer/m-p/1151495#M63992</link>
      <description>&lt;P&gt;If I wanted to update another field (3rd) from that same table how would I do that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;sourceFC = "C:/Temp/Temp.gdb/Table1"
where_clause = "MU LIKE '%TZ%'"
search_feats ={f[0]:(f[1:]} for f in arcpy.da.SearchCursor(sourceFC,["OBJECTID",'MU', 'KL'],where_clause)}
#searchVals = set(search_feats)
#print(search_feats)

with arcpy.da.UpdateCursor(sourceFC,["OBJECTID","MU_update", "KL_update"]) as upd_cur:
for upd_row in upd_cur:
    try:
       upd_row[1] = search_feats[upd_row[0]]
       upd_row[2] = search_feats[upd_row[0]][2] ????
       upd_cur.updateRow(upd_row)
    except:
       continue&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Mar 2022 21:56:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/basic-attribute-transfer/m-p/1151495#M63992</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2022-03-07T21:56:51Z</dc:date>
    </item>
    <item>
      <title>Re: Basic attribute transfer</title>
      <link>https://community.esri.com/t5/python-questions/basic-attribute-transfer/m-p/1151638#M63996</link>
      <description>&lt;P&gt;There's probably much better ways of doing this.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;sourceFC = "C:/Temp/Temp.gdb/Table1"
where_clause = "MU LIKE '%TZ%'"
search_feats ={f[0]:[f[1], f[2]] for f in arcpy.da.SearchCursor(sourceFC,["OBJECTID",'MU', 'KL'],where_clause)}
#searchVals = set(search_feats)
#print(search_feats)

with arcpy.da.UpdateCursor(sourceFC,["OBJECTID","MU_update", "KL_update"]) as upd_cur:
for upd_row in upd_cur:
    try:
       upd_row[1] = (search_feats[upd_row[0]])[0]
       upd_row[2] = (search_feats[upd_row[0]])[1]
       upd_cur.updateRow(upd_row)
    except:
       continue&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 08 Mar 2022 11:02:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/basic-attribute-transfer/m-p/1151638#M63996</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2022-03-08T11:02:59Z</dc:date>
    </item>
  </channel>
</rss>

