Newbie here.
I'm self-teaching about cursors and am practicing on this dataset. "testclass" is a feature class with an ID field (6 digit integer) and a name field. I want to go through and assign a unique name based on the ID. The following code works and illustrates more or less what I am trying to do (although I am sure it gives many of you heartburn with how clunky it is-- sorry
).
point <SPAN class="operator token">=</SPAN> <SPAN class="string token">"testclass"</SPAN>
update <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>UpdateCursor<SPAN class="punctuation token">(</SPAN>point<SPAN class="punctuation token">,</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="string token">"ID"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"name"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> update<SPAN class="punctuation token">:</SPAN>
ID <SPAN class="operator token">=</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>ID <SPAN class="operator token">==</SPAN> <SPAN class="string token">'174769'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
name <SPAN class="operator token">=</SPAN> <SPAN class="string token">"R4S8f"</SPAN>
row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> name
<SPAN class="keyword token">elif</SPAN> <SPAN class="punctuation token">(</SPAN>ID <SPAN class="operator token">==</SPAN> <SPAN class="string token">'174771'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
name <SPAN class="operator token">=</SPAN> <SPAN class="string token">"C3F8m"</SPAN>
row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> name
<SPAN class="keyword token">elif</SPAN> <SPAN class="punctuation token">(</SPAN>ID <SPAN class="operator token">==</SPAN> <SPAN class="string token">'174773'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
name <SPAN class="operator token">=</SPAN> <SPAN class="string token">"F4S8m"</SPAN>
row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> name
<SPAN class="keyword token">elif</SPAN> <SPAN class="punctuation token">(</SPAN>ID <SPAN class="operator token">==</SPAN> <SPAN class="string token">'174774'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
name <SPAN class="operator token">=</SPAN> <SPAN class="string token">"C1S8f"</SPAN>
row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> name
<SPAN class="keyword token">elif</SPAN> <SPAN class="punctuation token">(</SPAN>ID <SPAN class="operator token">==</SPAN> <SPAN class="string token">'174776'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
name <SPAN class="operator token">=</SPAN> <SPAN class="string token">"F3S8f"</SPAN>
row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> name
<SPAN class="keyword token">elif</SPAN> <SPAN class="punctuation token">(</SPAN>ID <SPAN class="operator token">==</SPAN> <SPAN class="string token">'174778'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
name <SPAN class="operator token">=</SPAN> <SPAN class="string token">"R1S8f"</SPAN>
row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> name
<SPAN class="keyword token">elif</SPAN> <SPAN class="punctuation token">(</SPAN>ID <SPAN class="operator token">==</SPAN> <SPAN class="string token">'174781'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
name <SPAN class="operator token">=</SPAN> <SPAN class="string token">"R6F8f"</SPAN>
row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> name
update<SPAN class="punctuation token">.</SPAN>updateRow<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>I would like to take this same concept and use an update cursor with a dictionary. I've found several posts online so I think I'm close but I can't quite get the syntax. This is what I have.
assignName <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="number token">174769</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'R4S8f'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">174771</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'C3F8m'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">174773</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'F4S8m'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">174774</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'C1S8f'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="number token">174776</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'F3S8f'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">174778</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'R1S8f'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">174781</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'R6F8f'</SPAN><SPAN class="punctuation token">}</SPAN>
cursor <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>UpdateCursor<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'testclass'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="string token">"ID"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"name"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> row<SPAN class="punctuation token">.</SPAN>ID <SPAN class="keyword token">in</SPAN> assignName<SPAN class="punctuation token">:</SPAN>
updateRow<SPAN class="punctuation token">.</SPAN>name <SPAN class="operator token">=</SPAN> assignName<SPAN class="punctuation token">[</SPAN>updateRow<SPAN class="punctuation token">.</SPAN>ID<SPAN class="punctuation token">]</SPAN>
update<SPAN class="punctuation token">.</SPAN>updateRow<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>It's telling me in line 7 "'list' object has no attribute 'ID'" when I run this in ArcGIS Pro.
Thanks in advance