0

When finding a solution to a problem by exploratory programming in a REPL I find it very useful to use print statements to build a log and provide insights into application state and flow.

Unfortunately ArcMap's Python Console seems to go silent after calling some of the geoprocessing tools.

For example:

>>> print("test 1")
... arcpy.ExcelToTable_conversion(source_path, target_sheet, source_sheet)
... print("test 2")
... 
test 1
>>> 

While if I remove the call to the Excel To Table tool:

>>> print("test 1")
... pass
... print("test 2")
... 
test 1
test 2

How can I reliably print to the console or otherwise work around this issue?

I am running:

  • ArcGIS Desktop 10.3.1.4959

I have read the following QAs on print or messaging in ArcPy but haven't found one that matches the use case of using the Python Console:

  • 2
    arcpy.AddMessage? – Michael Stimson Mar 6 '18 at 3:30
  • @MichaelStimson From the console? – Kelly Thomas Mar 6 '18 at 3:38
  • 1
    Have you tested this with another geoprocessing tool? I recall having issues with Excel to Table tools in 10.3.1. Is the tool failing? – Fezter Mar 6 '18 at 4:36
  • @ Fezter Excell To Table is completing without error and producing the correct data. However Get Count is not producing this behavior. – Kelly Thomas Mar 6 '18 at 4:54
1

There is something odd about the prompt of "..." that you get after your first print statement.

When I type print("test1") and use the Enter key I get a prompt of ">>>":

>>> print("test1")
test1
>>> 

I am using ArcGIS Desktop 10.6 but I will be surprised if this has changed since 10.3.


As a second test I typed these lines of code into IDLE, and then copied them to my paste buffer using Ctrl-V:

print("test1")
arcpy.GetCount_management(r"C:\Temp\test.gdb\TestFC2")
print("test2")

I pasted them into the Python window, followed by the Enter key twice and got the output below. I think this is the expected behaviour.

>>> print("test1")
... arcpy.GetCount_management(r"C:\Temp\test.gdb\TestFC2")
... print("test2")
... 
test1
test2
>>>
  • The three lines have been pasted as a unit. – Kelly Thomas Mar 6 '18 at 3:48
  • What were your precise steps to do that? – PolyGeo Mar 6 '18 at 3:51
  • Type in an external text editor (notepad++) then ctrl-c, ctrl-v. – Kelly Thomas Mar 6 '18 at 3:53
  • Try pasting each line in individually...I've seen similar behaviour when trying to paste a block of code into the Python console. – Dan Mar 6 '18 at 4:27
  • OK, print is working after GetCount but still silent after ExcelToTable. It looks like only some tools have this issue. – Kelly Thomas Mar 6 '18 at 4:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.