<?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: UpdateCursor error: fields size must match size of the row in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/updatecursor-error-fields-size-must-match-size-of/m-p/1507592#M71099</link>
    <description>&lt;P&gt;You're reading in two fields and returning (updating) one.You need to pass the same number and order of fields back to updateRow, even if you're not actually changing all of them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with arcpy.da.UpdateCursor (gdbTable, (addressField, zipField)) as zipCursor:
    for zipRow in zipCursor:
        street = zipRow[0]
        zipCode = street[-5:]
        zipRow = [street, zipCode]
        zipCursor.updateRow(zipRow)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 21 Jul 2024 01:18:44 GMT</pubDate>
    <dc:creator>Luke_Pinner</dc:creator>
    <dc:date>2024-07-21T01:18:44Z</dc:date>
    <item>
      <title>UpdateCursor error: fields size must match size of the row</title>
      <link>https://community.esri.com/t5/python-questions/updatecursor-error-fields-size-must-match-size-of/m-p/1507589#M71097</link>
      <description>&lt;P&gt;Using Pyscripter to take the last 5 characters (the ZIP code) of an address field and putting that into a separate field.&lt;/P&gt;&lt;P&gt;I am getting the following error:&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#FF0000"&gt;&lt;SPAN&gt;File&amp;nbsp;"C:\Users\battl\Desktop\experiment.py",&amp;nbsp;line&amp;nbsp;21,&amp;nbsp;in&amp;nbsp;&amp;lt;module&amp;gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;zipCursor.updateRow([zipRow])&lt;BR /&gt;TypeError:&amp;nbsp;fields&amp;nbsp;size&amp;nbsp;must&amp;nbsp;match&amp;nbsp;size&amp;nbsp;of&amp;nbsp;the&amp;nbsp;row&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;When I google it, it's saying that the zipRow at the end needs to be designated as a list (thus the square brackets, it doesn't work with or without them)&lt;/P&gt;&lt;P&gt;Here's my code:&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;arcpy&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;env&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;workspace&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;r"C:\GIS\VoteTally"&lt;BR /&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;gdbTable&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"\\Voters.gdb\\voterRecords"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;addressField&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&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nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;zipRow&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;zipCode&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;zipCursor&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;updateRow&lt;/SPAN&gt;&lt;SPAN&gt;([&lt;/SPAN&gt;&lt;SPAN&gt;zipRow&lt;/SPAN&gt;&lt;SPAN&gt;])&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Any help would be greatly appreciated.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Sat, 20 Jul 2024 23:23:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updatecursor-error-fields-size-must-match-size-of/m-p/1507589#M71097</guid>
      <dc:creator>JustinMuldowney</dc:creator>
      <dc:date>2024-07-20T23:23:54Z</dc:date>
    </item>
    <item>
      <title>Re: UpdateCursor error: fields size must match size of the row</title>
      <link>https://community.esri.com/t5/python-questions/updatecursor-error-fields-size-must-match-size-of/m-p/1507591#M71098</link>
      <description>&lt;P&gt;related error with solutions&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/python-questions/sequence-size-must-match-size-of-the-row/m-p/702192#M54412" target="_blank"&gt;Solved: sequence size must match size of the row - Esri Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/python-questions/updatecursor-quot-typeerror-sequence-size-must/td-p/73885" target="_blank" rel="noopener"&gt;Solved: UpdateCursor: "TypeError: sequence size must match... - Esri Community&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 21 Jul 2024 01:11:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updatecursor-error-fields-size-must-match-size-of/m-p/1507591#M71098</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2024-07-21T01:11:09Z</dc:date>
    </item>
    <item>
      <title>Re: UpdateCursor error: fields size must match size of the row</title>
      <link>https://community.esri.com/t5/python-questions/updatecursor-error-fields-size-must-match-size-of/m-p/1507592#M71099</link>
      <description>&lt;P&gt;You're reading in two fields and returning (updating) one.You need to pass the same number and order of fields back to updateRow, even if you're not actually changing all of them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with arcpy.da.UpdateCursor (gdbTable, (addressField, zipField)) as zipCursor:
    for zipRow in zipCursor:
        street = zipRow[0]
        zipCode = street[-5:]
        zipRow = [street, zipCode]
        zipCursor.updateRow(zipRow)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 21 Jul 2024 01:18:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updatecursor-error-fields-size-must-match-size-of/m-p/1507592#M71099</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2024-07-21T01:18:44Z</dc:date>
    </item>
    <item>
      <title>Re: UpdateCursor error: fields size must match size of the row</title>
      <link>https://community.esri.com/t5/python-questions/updatecursor-error-fields-size-must-match-size-of/m-p/1507710#M71100</link>
      <description>&lt;P&gt;That fixed the error I was seeing. It was then saying that street[-5:] was a None Type. When the table is created, it randomly added a completely Null row at 27096 (there's 140k). So it was getting tripped up there. I added a If row[0] is None delete row and it now works.&lt;BR /&gt;I also had to edit your line 5 to zipRow[1] = zipCode. The way you had it basically just copied the full street address into the zip field.&lt;/P&gt;&lt;P&gt;Thank you for the assist!&lt;/P&gt;</description>
      <pubDate>Sun, 21 Jul 2024 15:15:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updatecursor-error-fields-size-must-match-size-of/m-p/1507710#M71100</guid>
      <dc:creator>JustinMuldowney</dc:creator>
      <dc:date>2024-07-21T15:15:25Z</dc:date>
    </item>
    <item>
      <title>Re: UpdateCursor error: fields size must match size of the row</title>
      <link>https://community.esri.com/t5/python-questions/updatecursor-error-fields-size-must-match-size-of/m-p/1507848#M71102</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/816434"&gt;@JustinMuldowney&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;I also had to edit your line 5 to zipRow[1] = zipCode. The way you had it basically just copied the full street address into the zip field.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;No, that would do exactly the same as what I wrote, it would return the original street address in the first element and the zip code in the second.&lt;/P&gt;&lt;P&gt;e.g.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;zipRow = ["abc 12345", None]  # Some dummy data
street = zipRow[0]
zipCode = street[-5:]
zipRow[1] = zipCode 
print(zipRow == [street, zipCode])

True&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, 22 Jul 2024 10:25:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updatecursor-error-fields-size-must-match-size-of/m-p/1507848#M71102</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2024-07-22T10:25:28Z</dc:date>
    </item>
    <item>
      <title>Re: UpdateCursor error: fields size must match size of the row</title>
      <link>https://community.esri.com/t5/python-questions/updatecursor-error-fields-size-must-match-size-of/m-p/1508361#M71105</link>
      <description>&lt;P&gt;To add to this, always declare your field list/tuple as a single variable. If you are doing read and update operations and have to change a field it can become a nightmare if you forget to update the field order or field names somewhere down the line.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;**cursor_fields = (addressField, zipField)**&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then use that anywhere that you need those specific fields accessed.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jul 2024 01:55:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updatecursor-error-fields-size-must-match-size-of/m-p/1508361#M71105</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2024-07-23T01:55:02Z</dc:date>
    </item>
  </channel>
</rss>

