<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>idea Read print() as arcpy.AddMessage() (and vice versa) in Python Ideas</title>
    <link>https://community.esri.com/t5/python-ideas/read-print-as-arcpy-addmessage-and-vice-versa/idi-p/1630664</link>
    <description>&lt;P&gt;A continuing source of frustration is writing code as a notebook or py file before transferring it into a toolbox and having to find and replace all instances of print() with arcpy.AddMessage(). A similar thing happens in reverse: Sometimes I am copy-pasting code from my toolbox into the Python Window or something and need to change arcpy.AddMessage() to print().&lt;/P&gt;&lt;P&gt;I have seen people get around this by making a prnt(0 function:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def prnt(text):
    arcpy.AddMessage(text)
    print(text)&lt;/LI-CODE&gt;&lt;P&gt;It would really be better if the python window and notebooks just read arcpy.AddMessage/Error/Warning() as "print()", and if the geoprocessing pane read print() as "AddMessage()"&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 07 Jul 2025 14:42:08 GMT</pubDate>
    <dc:creator>AlfredBaldenweck</dc:creator>
    <dc:date>2025-07-07T14:42:08Z</dc:date>
    <item>
      <title>Read print() as arcpy.AddMessage() (and vice versa)</title>
      <link>https://community.esri.com/t5/python-ideas/read-print-as-arcpy-addmessage-and-vice-versa/idi-p/1630664</link>
      <description>&lt;P&gt;A continuing source of frustration is writing code as a notebook or py file before transferring it into a toolbox and having to find and replace all instances of print() with arcpy.AddMessage(). A similar thing happens in reverse: Sometimes I am copy-pasting code from my toolbox into the Python Window or something and need to change arcpy.AddMessage() to print().&lt;/P&gt;&lt;P&gt;I have seen people get around this by making a prnt(0 function:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def prnt(text):
    arcpy.AddMessage(text)
    print(text)&lt;/LI-CODE&gt;&lt;P&gt;It would really be better if the python window and notebooks just read arcpy.AddMessage/Error/Warning() as "print()", and if the geoprocessing pane read print() as "AddMessage()"&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jul 2025 14:42:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-ideas/read-print-as-arcpy-addmessage-and-vice-versa/idi-p/1630664</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2025-07-07T14:42:08Z</dc:date>
    </item>
    <item>
      <title>Re: Read print() as arcpy.AddMessage() (and vice versa)</title>
      <link>https://community.esri.com/t5/python-ideas/read-print-as-arcpy-addmessage-and-vice-versa/idc-p/1630675#M491</link>
      <description>&lt;P&gt;I agree that this would be a very nice QOL feature. The rout I personally took was to a log function that writes to a file in the project file so I can see the prints regardless of where I am running it however this comes with the draw back of if there are lots of print statements Notepad++ takes a bit to catch back up with the program flow.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jul 2025 15:03:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-ideas/read-print-as-arcpy-addmessage-and-vice-versa/idc-p/1630675#M491</guid>
      <dc:creator>GISDepartmentMFM</dc:creator>
      <dc:date>2025-07-07T15:03:51Z</dc:date>
    </item>
    <item>
      <title>Re: Read print() as arcpy.AddMessage() (and vice versa)</title>
      <link>https://community.esri.com/t5/python-ideas/read-print-as-arcpy-addmessage-and-vice-versa/idc-p/1630699#M492</link>
      <description>&lt;P&gt;Don't mess with existing python namespace, just create your own&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def tweet(msg):
    """Produce a message for both arcpy and python
    : msg - a text message
    """
    m = "{}".format(msg)
    arcpy.AddMessage(m)
    print(m)&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 07 Jul 2025 15:35:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-ideas/read-print-as-arcpy-addmessage-and-vice-versa/idc-p/1630699#M492</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2025-07-07T15:35:09Z</dc:date>
    </item>
    <item>
      <title>Re: Read print() as arcpy.AddMessage() (and vice versa)</title>
      <link>https://community.esri.com/t5/python-ideas/read-print-as-arcpy-addmessage-and-vice-versa/idc-p/1630716#M493</link>
      <description>&lt;P&gt;Yeah, that is the exact thing I don't want to do???&lt;/P&gt;&lt;P&gt;That requires me to copy an extra function into wherever I'm copy-pasting&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jul 2025 16:06:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-ideas/read-print-as-arcpy-addmessage-and-vice-versa/idc-p/1630716#M493</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2025-07-07T16:06:16Z</dc:date>
    </item>
    <item>
      <title>Re: Read print() as arcpy.AddMessage() (and vice versa)</title>
      <link>https://community.esri.com/t5/python-ideas/read-print-as-arcpy-addmessage-and-vice-versa/idc-p/1630770#M494</link>
      <description>&lt;P&gt;I just override builtins.print:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import builtins

def print(*values: object,
          sep: str = " ",
          end: str = "\n",
          file = None,
          flush: bool = False,
          severity: Literal['INFO', 'WARNING', 'ERROR'] = 'INFO'):
    """ Print a message to the ArcGIS Pro message queue and stdout
    set severity to 'WARNING' or 'ERROR' to print to the ArcGIS Pro message queue with the appropriate severity
    """

    # Print the message to stdout
    builtins.print(*values, sep=sep, end=end, file=file, flush=flush)
    
    end = "" if end == '\n' else end
    message = f"{sep.join(map(str, values))}{end}"
    # Print the message to the ArcGIS Pro message queue with the appropriate severity
    match severity:
        case "WARNING":
            arcpy.AddWarning(f"{message}")
        case "ERROR":
            arcpy.AddError(f"{message}")
        case _:
            arcpy.AddMessage(f"{message}")
    return&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Allowing this to be imported to shadow `print` should be safe since it maps properly to `print` and would allow existing code that uses print statements to also emit arcpy Messages. Here's a more complete version that implements the proper typing:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import builtins
import arcpy

from _typeshed import SupportsWrite, SupportsFlush, _T_contra
from typing import Protocol, Literal

class _SupportsWriteAndFlush(SupportsWrite[_T_contra], SupportsFlush, Protocol[_T_contra]): ...

def print(*values: object,
          sep: str | None = " ",
          end: str | None = "\n",
          file: _SupportsWriteAndFlush[str] | None = None,
          flush: bool = False,
          severity: Literal['INFO', 'WARNING', 'ERROR'] = 'INFO'):
    """ Print a message to the ArcGIS Pro message queue and stdout
    set severity to 'WARNING' or 'ERROR' to print to the ArcGIS Pro message queue with the appropriate severity
    """

    # Print the message to stdout
    builtins.print(*values, sep=sep, end=end, file=file, flush=flush)
    
    end = "" if end == '\n' else end
    message = f"{sep.join(map(str, values))}{end or ''}"
    # Print the message to the ArcGIS Pro message queue with the appropriate severity
    match severity:
        case "WARNING":
            arcpy.AddWarning(f"{message}")
        case "ERROR":
            arcpy.AddError(f"{message}")
        case _:
            arcpy.AddMessage(f"{message}")
    return&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 07 Jul 2025 17:50:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-ideas/read-print-as-arcpy-addmessage-and-vice-versa/idc-p/1630770#M494</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2025-07-07T17:50:59Z</dc:date>
    </item>
    <item>
      <title>Re: Read print() as arcpy.AddMessage() (and vice versa)</title>
      <link>https://community.esri.com/t5/python-ideas/read-print-as-arcpy-addmessage-and-vice-versa/idc-p/1630889#M495</link>
      <description>&lt;P&gt;Seems to be an ArcGIS Pro python console and notebook issue/feature...&amp;nbsp;&lt;/P&gt;&lt;P&gt;Calling arcpy.AddMessage(some_message) in a script or python console from an IDE or terminal will print to stdout.&amp;nbsp; But not from the ArcGIS Pro python consoles and notebooks.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jul 2025 22:20:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-ideas/read-print-as-arcpy-addmessage-and-vice-versa/idc-p/1630889#M495</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2025-07-07T22:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: Read print() as arcpy.AddMessage() (and vice versa)</title>
      <link>https://community.esri.com/t5/python-ideas/read-print-as-arcpy-addmessage-and-vice-versa/idc-p/1630916#M496</link>
      <description>&lt;P&gt;Huh. Not sure how I didn't notice that before, but yeah, AddError/Message/Warning do work just fine in like, PyCharm.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlfredBaldenweck_0-1751934667783.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/136041i5640559D94570DE9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AlfredBaldenweck_0-1751934667783.png" alt="AlfredBaldenweck_0-1751934667783.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
print("One")
arcpy.AddError("Two")
arcpy.AddMessage("Three")
arcpy.AddWarning("Four")
print("Five")&lt;/LI-CODE&gt;&lt;P&gt;Notebooks, however...&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlfredBaldenweck_1-1751934922214.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/136042i107407833072B7F9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AlfredBaldenweck_1-1751934922214.png" alt="AlfredBaldenweck_1-1751934922214.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jul 2025 00:35:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-ideas/read-print-as-arcpy-addmessage-and-vice-versa/idc-p/1630916#M496</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2025-07-08T00:35:38Z</dc:date>
    </item>
    <item>
      <title>Re: Read print() as arcpy.AddMessage() (and vice versa)</title>
      <link>https://community.esri.com/t5/python-ideas/read-print-as-arcpy-addmessage-and-vice-versa/idc-p/1660344#M527</link>
      <description>&lt;P&gt;Since I do 98% of my coding in PyCharm, I was also mildly baffled that the Python Window &amp;amp; Notebooks didn't honor the arcpy prints.&amp;nbsp; Now I'm really curious about what's different with the back end of the latter two.&lt;/P&gt;&lt;P&gt;Since it "just works" in an IDE, this leads me to suppose that ESRI might've reinvented the wheel on their built-in coding systems in suboptimal ways.&amp;nbsp; I'd love to see this specific problem addressed, but it also makes me wonder what other similarly weird quirks might still be waiting.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Oct 2025 04:25:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-ideas/read-print-as-arcpy-addmessage-and-vice-versa/idc-p/1660344#M527</guid>
      <dc:creator>MErikReedAugusta</dc:creator>
      <dc:date>2025-10-24T04:25:29Z</dc:date>
    </item>
  </channel>
</rss>

