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?
Solved! Go to Solution.
To make it work in both ArcMap and Pro, just make it a Unicode literal:
arcpy.AddMessage(u"\u200B")
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.
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.
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")
To make it work in both ArcMap and Pro, just make it a Unicode literal:
arcpy.AddMessage(u"\u200B")
Ahh yes, perfect!
Nice find Joshua!!!