<?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: Insert one (1) row into multiple empty table templates in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/insert-one-1-row-into-multiple-empty-table/m-p/1646041#M74666</link>
    <description>&lt;P&gt;Thanks for the that&lt;/P&gt;</description>
    <pubDate>Wed, 27 Aug 2025 13:16:34 GMT</pubDate>
    <dc:creator>SeanLukacs</dc:creator>
    <dc:date>2025-08-27T13:16:34Z</dc:date>
    <item>
      <title>Insert one (1) row into multiple empty table templates</title>
      <link>https://community.esri.com/t5/python-questions/insert-one-1-row-into-multiple-empty-table/m-p/1644691#M74640</link>
      <description>&lt;P&gt;Hello!&amp;nbsp; I am still learning the basics.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a several tables in a .gdb that I have assigned as a variable: (The reason being I am building a script tool for handling multiple fc and tables to generate a location based report on facilities and infrastructure.&amp;nbsp; I am creating template tables to then use when I run summary statistics, and I want to account for instances where some layers Objectid count == 0, in that case, a row is not generated, and then it causes issues when appending each layer to the final table even if to just say "0")&lt;/P&gt;&lt;P&gt;This is what I have:&lt;/P&gt;&lt;P&gt;import os&lt;BR /&gt;arcpy.env.workspace = r"path.gdb"&lt;/P&gt;&lt;P&gt;listTables = arcpy.ListTables("*qual_text")&lt;BR /&gt;print(listTables)&lt;BR /&gt;rows = arcpy.InsertCursor(listTables)&amp;lt;-----this is where it errors out "does not exist"&lt;/P&gt;&lt;P&gt;# Create 25 new rows. Set the initial row ID and distance values&lt;BR /&gt;for x in range(1):&lt;BR /&gt;row = rows.newRow()&lt;BR /&gt;row.setValue("FREQUENCY", 0)&lt;BR /&gt;row.setValue("COUNT_OBJECTID", 0)&lt;BR /&gt;row.setValue("FAC_TYPE", )&lt;BR /&gt;rows.insertRow(row)&lt;/P&gt;&lt;P&gt;# Delete cursor and row objects to remove locks on the data&lt;BR /&gt;del row&lt;BR /&gt;del rows&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;print("Row Added")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am getting an error about the tables not existing, but they print out and indeed do exist in the path I set.&amp;nbsp; do I have bad code formatting?&lt;/P&gt;&lt;P&gt;How do I use InsertCursor (or any other method) to insert 1 row with default values for fields (Already exist)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Fri, 22 Aug 2025 15:19:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/insert-one-1-row-into-multiple-empty-table/m-p/1644691#M74640</guid>
      <dc:creator>SeanLukacs</dc:creator>
      <dc:date>2025-08-22T15:19:26Z</dc:date>
    </item>
    <item>
      <title>Re: Insert one (1) row into multiple empty table templates</title>
      <link>https://community.esri.com/t5/python-questions/insert-one-1-row-into-multiple-empty-table/m-p/1644702#M74641</link>
      <description>&lt;P&gt;Once you have your list of tables, you need to address each table individually, start here:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;listTables = arcpy.ListTables("*qual_text")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;for table in listTables:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;rows = arcpy.InsertCursor(table)&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;listTables = arcpy.ListTables("*qual_text")

     for table in listTables:

          rows = arcpy.InsertCursor(table)&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 22 Aug 2025 16:23:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/insert-one-1-row-into-multiple-empty-table/m-p/1644702#M74641</guid>
      <dc:creator>Neal_t_k</dc:creator>
      <dc:date>2025-08-22T16:23:34Z</dc:date>
    </item>
    <item>
      <title>Re: Insert one (1) row into multiple empty table templates</title>
      <link>https://community.esri.com/t5/python-questions/insert-one-1-row-into-multiple-empty-table/m-p/1644711#M74642</link>
      <description>&lt;P&gt;&lt;A href="https://community.esri.com/t5/python-blog/code-formatting-the-community-version/ba-p/1007633" target="_blank"&gt;Code formatting ... the Community Version - Esri Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;to make it easier to read and refer to line numbers&lt;/P&gt;</description>
      <pubDate>Fri, 22 Aug 2025 16:22:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/insert-one-1-row-into-multiple-empty-table/m-p/1644711#M74642</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2025-08-22T16:22:05Z</dc:date>
    </item>
    <item>
      <title>Re: Insert one (1) row into multiple empty table templates</title>
      <link>https://community.esri.com/t5/python-questions/insert-one-1-row-into-multiple-empty-table/m-p/1644798#M74643</link>
      <description>&lt;P&gt;I don't think you can&amp;nbsp;create a cursor on this list. You must create a cursor for each individual table in that list.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try this,&lt;/P&gt;&lt;P&gt;Iterates table by table&lt;BR /&gt;Checks row count&lt;BR /&gt;Uses arcpy.da.InsertCursor&lt;/P&gt;&lt;LI-CODE lang="c"&gt;import arcpy

arcpy.env.workspace = r"path.gdb"
listTables = arcpy.ListTables("*qual_text")

for table_name in listTables:
    # Get the count of rows in the table
    count_int = int(arcpy.management.GetCount(table_name)[0])
    print(f"Table: {table_name} has {count_int} rows.")

    if count_int == 0:
        print("  Count is zero. Adding default row...")
        try:
            fields = ["FREQUENCY", "COUNT_OBJECTID", "FAC_TYPE"]
            with arcpy.da.InsertCursor(table_name, fields) as cursor:
                cursor.insertRow((0, 0, "No Features Present"))
            print("  Success!")
        except Exception as e:
            print(f"  Failed: {e}")
    else:
        print("  Count is not zero. Skipping.")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Aug 2025 18:09:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/insert-one-1-row-into-multiple-empty-table/m-p/1644798#M74643</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2025-08-22T18:09:54Z</dc:date>
    </item>
    <item>
      <title>Re: Insert one (1) row into multiple empty table templates</title>
      <link>https://community.esri.com/t5/python-questions/insert-one-1-row-into-multiple-empty-table/m-p/1644978#M74644</link>
      <description>&lt;P&gt;Here's a version that abuses comprehensions and a for...else block to check for empty tables with a single operation:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcpy.da import (
    SearchCursor,
    InsertCursor,
)

from arcpy import ListTables

def is_empty(table: str) -&amp;gt; bool:
    """This is a bit of a weird one that abuses a for ... else block
    to test if an iterator is empty. Since we don't want to waste time 
    counting the whole table, we can hop out early and only check the first
    record.
    
    the `else` block only executes if the break is never hit, an empty table
    will never begin iteration, so that break is never hit and False is returned. 
    If the table isn't empty, the loop immediately breaks and the else is skipped returning True
    
    The reason to do this is to take checking if a table is empty from O(n)
    to O(1) since we only ever need to look at the first record.
    """
    with SearchCursor(table, 'OID@') as cur:
        for _ in cur:
            break
        else:
            return True
        return False

def insert_row(table: str, vals: dict) -&amp;gt; None:
    with InsertCursor(table, list(vals.keys())) as cur:
        cur.insertRow(tuple(vals.values()))

def main():
    row = {"FREQUENCY": 0, "COUNT_OBJECTID": 0, "FAC_TYPE": "No Features Present"}
    tables = [t for t in ListTables("*qual_text") if is_empty(t)]
    updates = {
        insert_row(table, row) for table
        for table in tables
    }
    print(f'updated {updates} with default rows')

if __name__ == '__main__':
    main()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Aug 2025 16:14:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/insert-one-1-row-into-multiple-empty-table/m-p/1644978#M74644</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2025-08-23T16:14:02Z</dc:date>
    </item>
    <item>
      <title>Re: Insert one (1) row into multiple empty table templates</title>
      <link>https://community.esri.com/t5/python-questions/insert-one-1-row-into-multiple-empty-table/m-p/1646041#M74666</link>
      <description>&lt;P&gt;Thanks for the that&lt;/P&gt;</description>
      <pubDate>Wed, 27 Aug 2025 13:16:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/insert-one-1-row-into-multiple-empty-table/m-p/1646041#M74666</guid>
      <dc:creator>SeanLukacs</dc:creator>
      <dc:date>2025-08-27T13:16:34Z</dc:date>
    </item>
    <item>
      <title>Re: Insert one (1) row into multiple empty table templates</title>
      <link>https://community.esri.com/t5/python-questions/insert-one-1-row-into-multiple-empty-table/m-p/1646077#M74667</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/3265"&gt;@TonyAlmeida&lt;/a&gt;&amp;nbsp;This worked, like of the shelf, thank you!!&lt;/P&gt;</description>
      <pubDate>Wed, 27 Aug 2025 14:44:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/insert-one-1-row-into-multiple-empty-table/m-p/1646077#M74667</guid>
      <dc:creator>SeanLukacs</dc:creator>
      <dc:date>2025-08-27T14:44:20Z</dc:date>
    </item>
    <item>
      <title>Re: Insert one (1) row into multiple empty table templates</title>
      <link>https://community.esri.com/t5/python-questions/insert-one-1-row-into-multiple-empty-table/m-p/1646081#M74668</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/607017"&gt;@HaydenWelch&lt;/a&gt;&amp;nbsp; I am getting a syntax error at line 37 of your cell&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;    for table in tables
    ^
SyntaxError: invalid syntax&lt;/LI-CODE&gt;&lt;P&gt;. Is that For loop okay where it's at?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Aug 2025 14:45:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/insert-one-1-row-into-multiple-empty-table/m-p/1646081#M74668</guid>
      <dc:creator>SeanLukacs</dc:creator>
      <dc:date>2025-08-27T14:45:37Z</dc:date>
    </item>
    <item>
      <title>Re: Insert one (1) row into multiple empty table templates</title>
      <link>https://community.esri.com/t5/python-questions/insert-one-1-row-into-multiple-empty-table/m-p/1646283#M74669</link>
      <description>&lt;P&gt;I typoed on that line lol, there's 2 "for table" tokens. Just delete the one on like 36.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I shouldn't try to format python code on my phone...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think it was originally "or table" so you'd get a list of tables updated actually and autocorrect sniped me.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Aug 2025 21:11:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/insert-one-1-row-into-multiple-empty-table/m-p/1646283#M74669</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2025-08-27T21:11:03Z</dc:date>
    </item>
  </channel>
</rss>

