Why can't I see print text when running a script in ArcMap, but can view it when run in the python window of ArcMap?
I have a number of scripts that have a print function but don't show when run from the Toolbox.
1 Answer 1
arcpy.AddMessage()
BTW, recommended practice is to use
arcpy.AddMessage()
rather than print, for portability between command line/batch files and ArcMap. But print is fine if you don't want your message to display inside ArcMap.
Getting print statements in Python script to print through a batch file
-
and arcpy.AddWarning() and arcpy.AddError() - they all have their uses. You would/could use print() for debug information that you only want to show when running in python window (or on command line), the print() and arcpy.AddMessage() show in the python window but only the arcpy.AddMessage/Warning/Error will show in the geoprocessing tool window.Michael Stimson– Michael Stimson2015年04月17日 02:40:46 +00:00Commented Apr 17, 2015 at 2:40
-
I think this answer, including the quote from an earlier Q&A, is astray. I mostly agree with @MichaelMiles-Stimson but "arcpy.AddMessage() show in the python window" did not sound right to me so I tested to confirm my suspicion. I use
arcpy.AddMessage()
when I want to see a message in the geoprocessing progress dialog and/or in the JSON returned by geoprocessing services in response to REST API requests butprint
everywhere else.2015年04月19日 08:04:27 +00:00Commented Apr 19, 2015 at 8:04 -
@PolyGeo, I don't know about REST/JSON.. I don't do web (we all have to have limits and there are plenty of more capable developers that do web), I use print() for debug info and AddMessage (etc) as I generally use command line for testing (sometimes it's worth doing find & replace print with #print to turn it off); there is another level above that using open(DebugFile,'a') then writing strings to it, but again I don't know how that would work with web applications.Michael Stimson– Michael Stimson2015年04月19日 22:59:24 +00:00Commented Apr 19, 2015 at 22:59