<?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: Need help with script flow control in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/need-help-with-script-flow-control/m-p/133898#M10472</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks, Stacy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;That was the conclusion I had come to as well.&amp;nbsp; Exceptions are there for a reason--to break out of a block of code that's running inconsistantly.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again for your quick reply!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Matt&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 01 Sep 2011 17:15:10 GMT</pubDate>
    <dc:creator>MattFrancis</dc:creator>
    <dc:date>2011-09-01T17:15:10Z</dc:date>
    <item>
      <title>Need help with script flow control</title>
      <link>https://community.esri.com/t5/python-questions/need-help-with-script-flow-control/m-p/133896#M10470</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey All,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am running a script that will analyze feature classes, feature datasets, and tables in a workspace.&amp;nbsp; If I encounter a workspace that has no feature datasets (for example) the logic moves into the except statement and doesn't execute analyze on tables.&amp;nbsp; Instead of failling, I would like to see a warning in the output, but continue stepping through the try: block.&amp;nbsp; Any help is greatly appreciated!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;# Analyze
try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; env.workspace = dbconnection
&amp;nbsp;&amp;nbsp;&amp;nbsp; fclist = arcpy.ListFeatureClasses() #&amp;nbsp; &amp;lt;-- executes as expected
&amp;nbsp;&amp;nbsp;&amp;nbsp; for fc in fclist:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Analyze_management(fc,'BUSINESS;FEATURE;ADDS;DELETES')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output.write("&amp;nbsp; " + fc + " has been analyzed\n")&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 

&amp;nbsp;&amp;nbsp;&amp;nbsp; fdlist = arcpy.ListFeatureDatasets() #&amp;nbsp;&amp;nbsp; &amp;lt;-- FAIL!!!
&amp;nbsp;&amp;nbsp;&amp;nbsp; for fd in fdlist:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Analyze_management(fd,'BUSINESS;FEATURE;ADDS;DELETES')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output.write("&amp;nbsp; " + fd + " has been analyzed\n")

&amp;nbsp;&amp;nbsp;&amp;nbsp; tablist = arcpy.ListTables()&amp;nbsp; #&amp;nbsp; &amp;lt;-- Doesn't execute
&amp;nbsp;&amp;nbsp;&amp;nbsp; for tab in tablist:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Analyze_management(tab,'BUSINESS')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output.write("&amp;nbsp; " + tab + " has been analyzed\n")
&amp;nbsp;&amp;nbsp;&amp;nbsp; output.write("&amp;nbsp; arcpy.analyze finished successfully\n")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; output.write("!!arcpy.analyze didn't work right\n")
&amp;nbsp;&amp;nbsp;&amp;nbsp; err_list = str(sys.exc_info())
&amp;nbsp;&amp;nbsp;&amp;nbsp; for err in err_list.split('\\n'):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output.write("&amp;nbsp; " + err + "\n")
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Aug 2011 21:15:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-help-with-script-flow-control/m-p/133896#M10470</guid>
      <dc:creator>MattFrancis</dc:creator>
      <dc:date>2011-08-31T21:15:47Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with script flow control</title>
      <link>https://community.esri.com/t5/python-questions/need-help-with-script-flow-control/m-p/133897#M10471</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You should be able to just do a sub &lt;/SPAN&gt;&lt;STRONG&gt;try...except&lt;/STRONG&gt;&lt;SPAN&gt; statement around the thing that fails, like so:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Analyze
try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; env.workspace = dbconnection
&amp;nbsp;&amp;nbsp;&amp;nbsp; fclist = arcpy.ListFeatureClasses() #&amp;nbsp; &amp;lt;-- executes as expected
&amp;nbsp;&amp;nbsp;&amp;nbsp; for fc in fclist:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Analyze_management(fc,'BUSINESS;FEATURE;ADDS;DELETES')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output.write("&amp;nbsp; " + fc + " has been analyzed\n")&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 

&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fdlist = arcpy.ListFeatureDatasets() #&amp;nbsp;&amp;nbsp; &amp;lt;-- FAIL!!!
&amp;nbsp;&amp;nbsp;&amp;nbsp; except: # if you know the error, put it there, i.e. except ExecuteError:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fdlist = None
&amp;nbsp;&amp;nbsp;&amp;nbsp; if fdlist is not None:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for fd in fdlist:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Analyze_management(fd,'BUSINESS;FEATURE;ADDS;DELETES')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output.write("&amp;nbsp; " + fd + " has been analyzed\n")

&amp;nbsp;&amp;nbsp;&amp;nbsp; tablist = arcpy.ListTables()&amp;nbsp; #&amp;nbsp; &amp;lt;-- Doesn't execute
&amp;nbsp;&amp;nbsp;&amp;nbsp; for tab in tablist:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Analyze_management(tab,'BUSINESS')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output.write("&amp;nbsp; " + tab + " has been analyzed\n")
&amp;nbsp;&amp;nbsp;&amp;nbsp; output.write("&amp;nbsp; arcpy.analyze finished successfully\n")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; output.write("!!arcpy.analyze didn't work right\n")
&amp;nbsp;&amp;nbsp;&amp;nbsp; err_list = str(sys.exc_info())
&amp;nbsp;&amp;nbsp;&amp;nbsp; for err in err_list.split('\\n'):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output.write("&amp;nbsp; " + err + "\n")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The&lt;/SPAN&gt;&lt;STRONG&gt; if&lt;/STRONG&gt;&lt;SPAN&gt; statement stops it running the analysis if the dataset couldn't be found. You can copy this to the other ones as well, if there is any possibility your data set may not include feature classes or tables...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think I once had Arc hang indefinitely on a script with a sub&lt;/SPAN&gt;&lt;STRONG&gt; try...except&lt;/STRONG&gt;&lt;SPAN&gt;, but I was doing that as well as sub functions and multiprocessing, so it may have been related to doing those as well.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Let me know how you get on, as there are plenty of other ways to do this (if it does have a problem).&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:29:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-help-with-script-flow-control/m-p/133897#M10471</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2021-12-11T07:29:55Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with script flow control</title>
      <link>https://community.esri.com/t5/python-questions/need-help-with-script-flow-control/m-p/133898#M10472</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks, Stacy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;That was the conclusion I had come to as well.&amp;nbsp; Exceptions are there for a reason--to break out of a block of code that's running inconsistantly.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again for your quick reply!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Matt&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Sep 2011 17:15:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-help-with-script-flow-control/m-p/133898#M10472</guid>
      <dc:creator>MattFrancis</dc:creator>
      <dc:date>2011-09-01T17:15:10Z</dc:date>
    </item>
  </channel>
</rss>

