<?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: Add new row to empty file geodatabase table in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/add-new-row-to-empty-file-geodatabase-table/m-p/298814#M23140</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Result is not an integer you can compare how you are. You need this.&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;result = int(arcpy.GetCount_management(Variable1).getOutput(0))&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;Also don't forget to add this at the end of your script.&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;del addRow&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Yippee. It worked. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If results isn't an integer I can compare (and I am not doubting you) why did "0" (without quotes) return for the command "print results" for the empty tables?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Just trying to wrap my head around python.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks a zillion. I have been going around for hours on this snippet.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 04 Mar 2013 22:12:33 GMT</pubDate>
    <dc:creator>ClaudineSicker</dc:creator>
    <dc:date>2013-03-04T22:12:33Z</dc:date>
    <item>
      <title>Add new row to empty file geodatabase table</title>
      <link>https://community.esri.com/t5/python-questions/add-new-row-to-empty-file-geodatabase-table/m-p/298810#M23136</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am using ArcGIS 10.1 and have created a script that checks to see if a file geodatabase table is empty. It is a table with no spatial referencing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The code I have thus far can add rows to tables that already have a record in it, but it will not add a new row to an empty table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Can this be done? Would it be better accomplished if it were a dbf file rather than a geodatabase table?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Snippet of code looks like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; addRow =arcpy.da.InsertCursor(Variable1,("Frequency", "Used", "Region"))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = arcpy.GetCount_management(Variable1)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print result&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print addRow&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if result == 0:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [indent]addRow.insertRow((0, "Locally", 3))[/indent]&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [indent]do something else[/indent]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;result and addRow printouts are correct. Prior tests taking out the if, else statements and just running the addRow.insertRow statement showed that tables that have at least one record get appended with a new row.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So I am of the opinion that I cannot add a new row using this approach. Any other ideas as to how I can add a row to an empty table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Many thanks.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Mar 2013 19:34:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-new-row-to-empty-file-geodatabase-table/m-p/298810#M23136</guid>
      <dc:creator>ClaudineSicker</dc:creator>
      <dc:date>2013-03-04T19:34:57Z</dc:date>
    </item>
    <item>
      <title>Re: Add new row to empty file geodatabase table</title>
      <link>https://community.esri.com/t5/python-questions/add-new-row-to-empty-file-geodatabase-table/m-p/298811#M23137</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Does the empty table have the fields you are trying to populate?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Mar 2013 20:25:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-new-row-to-empty-file-geodatabase-table/m-p/298811#M23137</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2013-03-04T20:25:44Z</dc:date>
    </item>
    <item>
      <title>Re: Add new row to empty file geodatabase table</title>
      <link>https://community.esri.com/t5/python-questions/add-new-row-to-empty-file-geodatabase-table/m-p/298812#M23138</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Does the empty table have the fields you are trying to populate?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes. the fields referenced in the addRow variable ("Frequency", "Used", "Region")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want to populate them with (0, "Locally", 3)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Mar 2013 20:45:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-new-row-to-empty-file-geodatabase-table/m-p/298812#M23138</guid>
      <dc:creator>ClaudineSicker</dc:creator>
      <dc:date>2013-03-04T20:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: Add new row to empty file geodatabase table</title>
      <link>https://community.esri.com/t5/python-questions/add-new-row-to-empty-file-geodatabase-table/m-p/298813#M23139</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Result is not an integer you can compare how you are. You need this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;result = int(arcpy.GetCount_management(Variable1).getOutput(0))&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also don't forget to add this at the end of your script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;del addRow&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Mar 2013 21:39:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-new-row-to-empty-file-geodatabase-table/m-p/298813#M23139</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2013-03-04T21:39:55Z</dc:date>
    </item>
    <item>
      <title>Re: Add new row to empty file geodatabase table</title>
      <link>https://community.esri.com/t5/python-questions/add-new-row-to-empty-file-geodatabase-table/m-p/298814#M23140</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Result is not an integer you can compare how you are. You need this.&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;result = int(arcpy.GetCount_management(Variable1).getOutput(0))&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;Also don't forget to add this at the end of your script.&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;del addRow&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Yippee. It worked. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If results isn't an integer I can compare (and I am not doubting you) why did "0" (without quotes) return for the command "print results" for the empty tables?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Just trying to wrap my head around python.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks a zillion. I have been going around for hours on this snippet.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Mar 2013 22:12:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-new-row-to-empty-file-geodatabase-table/m-p/298814#M23140</guid>
      <dc:creator>ClaudineSicker</dc:creator>
      <dc:date>2013-03-04T22:12:33Z</dc:date>
    </item>
    <item>
      <title>Re: Add new row to empty file geodatabase table</title>
      <link>https://community.esri.com/t5/python-questions/add-new-row-to-empty-file-geodatabase-table/m-p/298815#M23141</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If you want to get as much information as possible about an output or variable you can use the following commands.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;type(variable)
repr(variable)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Which shows the value returned by GetCount is an object.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; result = arcpy.GetCount_management(fc)
&amp;gt;&amp;gt;&amp;gt; type(result)
&amp;lt;class 'arcpy.arcobjects.arcobjects.Result'&amp;gt;
&amp;gt;&amp;gt;&amp;gt; repr(result)
"&amp;lt;Result '60'&amp;gt;"&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Which you must then get the results property from. But we're still not done yet.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; result = arcpy.GetCount_management(fc).getOutput(0)
&amp;gt;&amp;gt;&amp;gt; type(result)
&amp;lt;type 'unicode'&amp;gt;
&amp;gt;&amp;gt;&amp;gt; repr(result)
"u'60'"
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The getOutput parameter returns a unicode string, not an int. But once we are here it is a simple step to convert it to a numeric value.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; result = int(arcpy.GetCount_management(fc).getOutput(0))
&amp;gt;&amp;gt;&amp;gt; type(result)
&amp;lt;type 'int'&amp;gt;
&amp;gt;&amp;gt;&amp;gt; repr(result)
'60'&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope that helps.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:21:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-new-row-to-empty-file-geodatabase-table/m-p/298815#M23141</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-11T14:21:14Z</dc:date>
    </item>
  </channel>
</rss>

