<?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: Help with looping in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/help-with-looping/m-p/94014#M7337</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Sean,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os
from arcpy import env
env.overwriteOutput = 1
env.workspace = r"C:\Workspace\CaseTypeTables.gdb"

lstTables = arcpy.ListTables("*")
for table in lstTables:
&amp;nbsp;&amp;nbsp;&amp;nbsp; cttable = arcpy.mapping.TableView(table)
&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportReport(cttable, r"C:\Workspace\working\LAS_case-type_report.rlf", r"C:\Workspace\working\successPDFreport.pdf" + os.sep + table + "_PDFreport.pdf")
&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.GetMessages()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Dec 2021 23:35:42 GMT</pubDate>
    <dc:creator>JakeSkinner</dc:creator>
    <dc:date>2021-12-10T23:35:42Z</dc:date>
    <item>
      <title>Help with looping</title>
      <link>https://community.esri.com/t5/python-questions/help-with-looping/m-p/94013#M7336</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I'm new to arcmapping and modelbuilder. My first task was create a model (fig 1) to run thru a .gdb, check for a certain field, then run the frequency tool, and output the resulting table to a different .gdb. It works exactly as I want it. Now I want to take each those tables (about 50 of them) and create a report (.rlf) and export it to PDF. The code below, which I've loaded as a script into a toolbox, works correctly but only one table at a time. How can I (1) loop it thru each table? and (2) not overwrite the previous PDF?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Ultimately I want to insert it to the first model ( Fig 1)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help or suggestions would be greatly appreciated &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy&amp;nbsp; cttable=arcpy.mapping.TableView(r"C:\Workspace\CaseTypeTables.gdb\AGR_SET_RECON_LN_case_types") arcpy.mapping.ExportReport(cttable,r"C:\Workspace\working\LAS_case-type_report.rlf",r"C:\Workspace\working\successPDFreport.pdf") del cttable&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Aug 2012 22:12:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-with-looping/m-p/94013#M7336</guid>
      <dc:creator>SeanConlon</dc:creator>
      <dc:date>2012-08-29T22:12:15Z</dc:date>
    </item>
    <item>
      <title>Re: Help with looping</title>
      <link>https://community.esri.com/t5/python-questions/help-with-looping/m-p/94014#M7337</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Sean,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, os
from arcpy import env
env.overwriteOutput = 1
env.workspace = r"C:\Workspace\CaseTypeTables.gdb"

lstTables = arcpy.ListTables("*")
for table in lstTables:
&amp;nbsp;&amp;nbsp;&amp;nbsp; cttable = arcpy.mapping.TableView(table)
&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportReport(cttable, r"C:\Workspace\working\LAS_case-type_report.rlf", r"C:\Workspace\working\successPDFreport.pdf" + os.sep + table + "_PDFreport.pdf")
&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.GetMessages()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 23:35:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-with-looping/m-p/94014#M7337</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-10T23:35:42Z</dc:date>
    </item>
    <item>
      <title>Re: Help with looping</title>
      <link>https://community.esri.com/t5/python-questions/help-with-looping/m-p/94015#M7338</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;hi Jake&amp;nbsp; thanks for replying so quickly!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It works!!!!!! and not only that I was able to plug it into that original model ( fig 1, from above ) and it works exactly that it's supposed to. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I did have to tweak one thing - deleting the "+os.sep" from line 10. I don't know why it works without it but it does. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;below is the current working version, with comments. I know its not the way your supposed to do it but it helps this novice understand whats going on.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;some questions though&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1. what does the * do?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. what does the get message () do?&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;# import arcpy modules and geoprocessing tools import arcpy, os # not sure what this does from arcpy import env # enables the output to overwrite anything that was there before env.overwriteOutput = 1 # not sure what this does&amp;nbsp; env.workspace = r"C:\Workspace\CaseTypeTables.gdb"&amp;nbsp; #1sttables is a variable that contains a list of all the tables from casetypetables.gdb #what is the * for&amp;nbsp; lstTables = arcpy.ListTables("*")&amp;nbsp;&amp;nbsp; #loop to run thru all the tables in 1sttables and execute the exportreport function from arcpy #table is a variable for a single table from 1sttable #cttable is a variable calling the arcpy funtion tableview to view the single table #the TRY&amp;nbsp; command is executing the exportreport function on cttable using the report format from # LAS_case-type_report.rlf and exporting the resulting PDF at C:\workspace\. . . . for table in lstTables: &amp;nbsp;&amp;nbsp;&amp;nbsp; cttable = arcpy.mapping.TableView(table) &amp;nbsp;&amp;nbsp;&amp;nbsp; try: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.ExportReport(cttable, r"C:\Workspace\working\LAS_case-type_report.rlf", r"C:\Workspace\working\_"+table+".pdf") &amp;nbsp;&amp;nbsp;&amp;nbsp; except: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.GetMessages()&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Aug 2012 22:03:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-with-looping/m-p/94015#M7338</guid>
      <dc:creator>SeanConlon</dc:creator>
      <dc:date>2012-08-30T22:03:31Z</dc:date>
    </item>
    <item>
      <title>Re: Help with looping</title>
      <link>https://community.esri.com/t5/python-questions/help-with-looping/m-p/94016#M7339</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;1. what does the * do?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-This is a wildcard.&amp;nbsp; Specifying this tell the function to list all tables within your geodatabase.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2. what does the get message () do?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-This reports any errors/warnings that may occur when you try to execute a command.&amp;nbsp; For example, if the 'arcpy.mapping.ExportReport' function failed, it would output the error messages.&amp;nbsp; More information can be found &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//018v00000008000000"&gt;here&lt;/A&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Aug 2012 11:15:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-with-looping/m-p/94016#M7339</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2012-08-31T11:15:43Z</dc:date>
    </item>
  </channel>
</rss>

