<?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: Python scripts - Print statements and arcpy.AddMessage in Developers Questions</title>
    <link>https://community.esri.com/t5/developers-questions/python-scripts-print-statements-and-arcpy/m-p/202801#M1222</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The question remains open and assumed answered and it appears that there were no useful suggestions&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 09 Jul 2014 22:56:58 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2014-07-09T22:56:58Z</dc:date>
    <item>
      <title>Python scripts - Print statements and arcpy.AddMessage</title>
      <link>https://community.esri.com/t5/developers-questions/python-scripts-print-statements-and-arcpy/m-p/202796#M1217</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Through Pythonwin I have created a collection of scripts that I have incorporated into an ArcToolbox. I have shared this toolbox with several colleagues and clients. When developing scripts I use print statements to track the progression of test runs. After I have finished developing my scripts they are typically run through ArcToolbox; however, when there are occasions when I have to run a script repeatedly to process data for several large extents I will setup a batch file so processing can run through unattended.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My question:&lt;/P&gt;&lt;P&gt;Use of print statements will write messages to the screen when running a script through an IDE. Use of arcpy.AddMessage will write messages to the screen when running a script through an ArcToolbox script tool. What is the best way to setup a Python script to write messages to the screen whether the script is being run through an IDE or ArcToolbox? Is there code that can identify where the script is running from (i.e. through either an IDE or through a script tool in ArcToolbox) and write messages to the screen using print statements or arcpy.AddMessage, whichever is appropriate?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance for any comments/feedback!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Jul 2014 18:57:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/python-scripts-print-statements-and-arcpy/m-p/202796#M1217</guid>
      <dc:creator>DarrenMcCormick</dc:creator>
      <dc:date>2014-07-09T18:57:16Z</dc:date>
    </item>
    <item>
      <title>Re: Python scripts - Print statements and arcpy.AddMessage</title>
      <link>https://community.esri.com/t5/developers-questions/python-scripts-print-statements-and-arcpy/m-p/202797#M1218</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;From my blog &lt;A href="http://obidangis.blogspot.ca/2013/06/how-to-print-messages-regardless-of.html" title="http://obidangis.blogspot.ca/2013/06/how-to-print-messages-regardless-of.html"&gt;ObiDanGIS's Geomatics Blog: How to print messages regardless of whether you are running a standalone script or from with…&lt;/A&gt;‌&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Jul 2014 19:05:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/python-scripts-print-statements-and-arcpy/m-p/202797#M1218</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-07-09T19:05:54Z</dc:date>
    </item>
    <item>
      <title>Re: Python scripts - Print statements and arcpy.AddMessage</title>
      <link>https://community.esri.com/t5/developers-questions/python-scripts-print-statements-and-arcpy/m-p/202798#M1219</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't know of any modules/classes to identify if the script is running from ArcGIS toolbox vs. Python IDE.&amp;nbsp; However, I have also run into this very thing.&amp;nbsp; Here is my solution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a simple function I wrote to handle this type of thing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;# Function to write info to log file&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;# passing a value of 1 along with the msg will log in info to a file, otherwise the function will just a print a message&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;def loginfo(msg, loglevel):&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if loglevel == 1:&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; log = open(logfile,'a')&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; log.write('\n---------')&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; log.write(msg)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; log.close()&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print msg&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(msg)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print msg&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(msg)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's pretty simple function that takes a message string and an integer.&amp;nbsp; It's pretty standard in all my scripts (I should create it as a module/class so I can import it).&amp;nbsp; If you want to use it make sure to create a logfile variable with a path to a file to log to.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Jul 2014 19:06:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/python-scripts-print-statements-and-arcpy/m-p/202798#M1219</guid>
      <dc:creator>IanGrasshoff</dc:creator>
      <dc:date>2014-07-09T19:06:43Z</dc:date>
    </item>
    <item>
      <title>Re: Python scripts - Print statements and arcpy.AddMessage</title>
      <link>https://community.esri.com/t5/developers-questions/python-scripts-print-statements-and-arcpy/m-p/202799#M1220</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Print statements will display in ArcMap's Python window for Add-In tools.&amp;nbsp; Not sure if that helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Jul 2014 19:11:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/python-scripts-print-statements-and-arcpy/m-p/202799#M1220</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2014-07-09T19:11:06Z</dc:date>
    </item>
    <item>
      <title>Re: Python scripts - Print statements and arcpy.AddMessage</title>
      <link>https://community.esri.com/t5/developers-questions/python-scripts-print-statements-and-arcpy/m-p/202800#M1221</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks to Dan, Ian, and James who have each experienced this issue and have proposed workable solutions. I find myself in a difficult position in having to select which is the "Correct Answer".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Darren&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Jul 2014 20:12:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/python-scripts-print-statements-and-arcpy/m-p/202800#M1221</guid>
      <dc:creator>DarrenMcCormick</dc:creator>
      <dc:date>2014-07-09T20:12:14Z</dc:date>
    </item>
    <item>
      <title>Re: Python scripts - Print statements and arcpy.AddMessage</title>
      <link>https://community.esri.com/t5/developers-questions/python-scripts-print-statements-and-arcpy/m-p/202801#M1222</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The question remains open and assumed answered and it appears that there were no useful suggestions&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Jul 2014 22:56:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/python-scripts-print-statements-and-arcpy/m-p/202801#M1222</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-07-09T22:56:58Z</dc:date>
    </item>
  </channel>
</rss>

