<?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 Brain cramp with an Insert Cursor in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/brain-cramp-with-an-insert-cursor/m-p/127850#M9922</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm developing a script that creates a table adds fields and then populates the values of those fields.&amp;nbsp; I'm good with creating the table and adding the fields, it's the insert cursor that's giving me grief.&amp;nbsp; (Perhaps I'm giving the insert cursor grief; it's friday afternoon after all...)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let's call the table newTable, I have list of the values for each of the fields in order:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;# the list values looks like this:&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;101&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; u&lt;SPAN class="string token"&gt;'Salt Lake County'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; u&lt;SPAN class="string token"&gt;'Jordan School District'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; u&lt;SPAN class="string token"&gt;'South Jordan City'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; u&lt;SPAN class="string token"&gt;'South Salt Lake Valley Mosquito Abatement District'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; u&lt;SPAN class="string token"&gt;'Jordan Valley Water Conservancy District'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; u&lt;SPAN class="string token"&gt;'Jordan/Canyons Debt Service Area'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; u&lt;SPAN class="string token"&gt;'Central Utah Water Conservancy District'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; u&lt;SPAN class="string token"&gt;'Crescent Cemetery District'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; u&lt;SPAN class="string token"&gt;'South Valley Sewer District'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;However,&amp;nbsp; when I try to use the list as the source, it errors out with &lt;EM&gt;TypeError: sequence&amp;nbsp;size must match size of the row.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can see where the issue is: when I perform arcpy.ListFields(newTable) I get 11 fields.&amp;nbsp; But, but the length of my list of values is 10: the difference being the objectid.&amp;nbsp; I don't quite understand how to accommodate for the OID and the subsequent difference in row size vs the number of list elements.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 07:14:00 GMT</pubDate>
    <dc:creator>JoeBorgione</dc:creator>
    <dc:date>2021-12-11T07:14:00Z</dc:date>
    <item>
      <title>Brain cramp with an Insert Cursor</title>
      <link>https://community.esri.com/t5/python-questions/brain-cramp-with-an-insert-cursor/m-p/127850#M9922</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm developing a script that creates a table adds fields and then populates the values of those fields.&amp;nbsp; I'm good with creating the table and adding the fields, it's the insert cursor that's giving me grief.&amp;nbsp; (Perhaps I'm giving the insert cursor grief; it's friday afternoon after all...)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let's call the table newTable, I have list of the values for each of the fields in order:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;# the list values looks like this:&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;101&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; u&lt;SPAN class="string token"&gt;'Salt Lake County'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; u&lt;SPAN class="string token"&gt;'Jordan School District'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; u&lt;SPAN class="string token"&gt;'South Jordan City'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; u&lt;SPAN class="string token"&gt;'South Salt Lake Valley Mosquito Abatement District'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; u&lt;SPAN class="string token"&gt;'Jordan Valley Water Conservancy District'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; u&lt;SPAN class="string token"&gt;'Jordan/Canyons Debt Service Area'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; u&lt;SPAN class="string token"&gt;'Central Utah Water Conservancy District'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; u&lt;SPAN class="string token"&gt;'Crescent Cemetery District'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; u&lt;SPAN class="string token"&gt;'South Valley Sewer District'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;However,&amp;nbsp; when I try to use the list as the source, it errors out with &lt;EM&gt;TypeError: sequence&amp;nbsp;size must match size of the row.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can see where the issue is: when I perform arcpy.ListFields(newTable) I get 11 fields.&amp;nbsp; But, but the length of my list of values is 10: the difference being the objectid.&amp;nbsp; I don't quite understand how to accommodate for the OID and the subsequent difference in row size vs the number of list elements.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:14:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/brain-cramp-with-an-insert-cursor/m-p/127850#M9922</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-12-11T07:14:00Z</dc:date>
    </item>
    <item>
      <title>Re: Brain cramp with an Insert Cursor</title>
      <link>https://community.esri.com/t5/python-questions/brain-cramp-with-an-insert-cursor/m-p/127851#M9923</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Got it....&amp;nbsp; And late on Friday afternoon....&amp;nbsp; Here you go:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I originally opened the insert cursor like this:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;cursor &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;InsertCursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;newTable&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'*'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Which makes available all fields for the insert cursor including the OID. My solution is to create a list of fields with the arcpy.ListFields() function, pop the first element off that list and then write the name values of the weird list objects.&amp;nbsp; It's that last list I then pass to the insert cursor and my lengths are all good:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;myFields = arcpy.ListFields(newTable) # create a list of list objects
x = myFields.pop(0)&amp;nbsp;&amp;nbsp;&amp;nbsp; #gets rid of the oid
fields = []
for f in myFeilds:
&amp;nbsp; fields.append(f.name) # gets all the field names into the new list call fields

cursor = arcpy.da.InsertCursor(newTable,fields)&amp;nbsp; #open a cursor for all fields,sans OID
cursor.insertRow(values) # add the values from my original post above
del cursor


‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:14:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/brain-cramp-with-an-insert-cursor/m-p/127851#M9923</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-12-11T07:14:03Z</dc:date>
    </item>
    <item>
      <title>Re: Brain cramp with an Insert Cursor</title>
      <link>https://community.esri.com/t5/python-questions/brain-cramp-with-an-insert-cursor/m-p/127852#M9924</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Glad you got it sorted out.&amp;nbsp; I strongly discourage the use of asterisks for field column mapping with cursors.&amp;nbsp; In talking with Esri product teams, there was some debate about not allowing them for performance, maintainability, and troubleshooting reasons; but convenience took the day.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Whether using asterisks or not, if you have OID as a field with your insert cursor, just pass it None and it will auto populate.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 May 2018 22:26:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/brain-cramp-with-an-insert-cursor/m-p/127852#M9924</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2018-05-18T22:26:49Z</dc:date>
    </item>
    <item>
      <title>Re: Brain cramp with an Insert Cursor</title>
      <link>https://community.esri.com/t5/python-questions/brain-cramp-with-an-insert-cursor/m-p/127853#M9925</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Okay- passing it None makes sense too. And yes, I agree after today's lesson, '*' is just looking for trouble!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/3420"&gt;Joshua Bixby&lt;/A&gt;‌&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 May 2018 22:36:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/brain-cramp-with-an-insert-cursor/m-p/127853#M9925</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2018-05-18T22:36:50Z</dc:date>
    </item>
    <item>
      <title>Re: Brain cramp with an Insert Cursor</title>
      <link>https://community.esri.com/t5/python-questions/brain-cramp-with-an-insert-cursor/m-p/127854#M9926</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;line 1, 2&amp;nbsp; myFields &lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #3d3d3d; font-family: Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px; word-wrap: break-word;"&gt;check line 4 ... OCD day&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;myFields &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ListFields&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;newTable&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# create a list of list objects&lt;/SPAN&gt;
x &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; myFields&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;pop&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="comment token"&gt;#gets rid of the oid&lt;/SPAN&gt;
fields &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; f &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; myFields&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp; fields&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;append&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;f&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;name&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# gets&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# ---- or to reduce spelling errors&lt;/SPAN&gt;

fields &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;f&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;name &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; f &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ListFields&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;newTable&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&amp;nbsp; &lt;SPAN class="comment token"&gt;# ---- drop the 1st field&lt;/SPAN&gt;
&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:14:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/brain-cramp-with-an-insert-cursor/m-p/127854#M9926</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T07:14:05Z</dc:date>
    </item>
    <item>
      <title>Re: Brain cramp with an Insert Cursor</title>
      <link>https://community.esri.com/t5/python-questions/brain-cramp-with-an-insert-cursor/m-p/127855#M9927</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HAHAHA.&amp;nbsp; I noticed that too but gave it a what the heck it's Friday!&amp;nbsp; Like minds....&amp;nbsp;&amp;nbsp;&lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/wink.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 May 2018 23:49:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/brain-cramp-with-an-insert-cursor/m-p/127855#M9927</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2018-05-18T23:49:13Z</dc:date>
    </item>
  </channel>
</rss>

