AnsweredAssumed Answered

Python scripts - Print statements and arcpy.AddMessage

Question asked by dmccormick on Jul 9, 2014
Latest reply on Jul 9, 2014 by Dan_Patterson



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.


My question:

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?


Thanks in advance for any comments/feedback!