arcpy.AddMessage does not produce newlines in ArcGIS Pro?

2606
6
Jump to solution
05-03-2020 11:19 PM
GB_MattPanunto_GISS
Occasional Contributor II

I am working with ArcGIS Pro v2.4.1, and am trying to produce newlines using arcpy.AddMessage when running a script tool. I just want to create some blank spaces between messages, but none of the following seem to work when running the tool in ArcGIS Pro:

arcpy.AddMessage("\n")

arcpy.AddMessage("")

arcpy.AddMessage(" ")

 

However, these do work when running the tool in ArcMap. Is there a reason why these might not work in ArcGIS Pro?

0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

To make it work in both ArcMap and Pro, just make it a Unicode literal:

arcpy.AddMessage(u"\u200B") ‍‍

View solution in original post

6 Replies
FC_Basson
MVP Regular Contributor

I think it is getting ignored or "trimmed".

I tested this code

import arcpy
arcpy.AddMessage("first line")
arcpy.AddMessage("\n ")
arcpy.AddMessage(".\n")
arcpy.AddMessage(".")
arcpy.AddMessage("second line")
arcpy.AddMessage("first line\nsecond line")‍‍‍‍‍‍

and got this output

So you might need to use an additional character to create a spacing between output lines.

JoshuaBixby
MVP Esteemed Contributor

I see the same thing as FC Basson‌ with Pro 2.5.  Personally, I would consider this a defect on Esri's part, but maybe they would consider it an 'enhancement' with Pro!

I tested a few white-space and control characters and all were getting stripped, but I did find that a zero-width space ('\u200B') works.

GB_MattPanunto_GISS
Occasional Contributor II

Good find! The '\u200B' seems to be working for me as well, but only for ArcGIS Pro, not ArcMap, ugh.

I guess inserting this line will provide a space in both environments:

arcpy.AddMessage("\u200B" if (sys.version_info[0] == 3) else "\n")

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

To make it work in both ArcMap and Pro, just make it a Unicode literal:

arcpy.AddMessage(u"\u200B") ‍‍
GB_MattPanunto_GISS
Occasional Contributor II

Ahh yes, perfect!

0 Kudos
MichaelVolz
Esteemed Contributor

Nice find Joshua!!!

0 Kudos