<?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>topic Re: writing arcpy.GetMessages() to a text file? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/writing-arcpy-getmessages-to-a-text-file/m-p/1002641#M59082</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do you script out the location of the txt file / is there more to the script than what has been shared on this thread.&lt;/P&gt;&lt;P&gt;I am wanting to extract the Message from geocoding results and log them in a txt file with the corresponding txt file that is created when you "Save A Python Script", since doing that does not bring along the messages.&lt;/P&gt;&lt;P&gt;In this thread it is said to manually copy and paste the messages to a txt file directly from the GP History log pane in Pro&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/modelbuilder-questions/model-builder-can-i-write-text-from-results-window-outputs-to/td-p/857924" target="_self"&gt;https://community.esri.com/t5/modelbuilder-questions/model-builder-can-i-write-text-from-results-window-outputs-to/td-p/857924&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 797px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/475iEEDA8A9852EFD008/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;It would be nice to be able to run weekly geocoder rebuilds and geocode our address data against our actual and theoretical address ranges along with a fishbone analysis to track and log the progress and accuracy of our address data, especially since this data is shared with our communications people.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
    <pubDate>Wed, 18 Nov 2020 18:40:07 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2020-11-18T18:40:07Z</dc:date>
    <item>
      <title>writing arcpy.GetMessages() to a text file?</title>
      <link>https://community.esri.com/t5/python-questions/writing-arcpy-getmessages-to-a-text-file/m-p/171418#M13177</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is there anything wrong with this very simplistic way of writing geo-processing messages to a plain text file? Being new to Python, I was surprised it was this easy....I must be overlooking something!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To clarify, I am intending to write the messages from the last tool which was invoked in the script.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;f &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; open&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;resultLogFile&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"a"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

s &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; str&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;GetMessages&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
f&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;write&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;s&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:52:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-arcpy-getmessages-to-a-text-file/m-p/171418#M13177</guid>
      <dc:creator>KeithD1</dc:creator>
      <dc:date>2021-12-11T08:52:55Z</dc:date>
    </item>
    <item>
      <title>Re: writing arcpy.GetMessages() to a text file?</title>
      <link>https://community.esri.com/t5/python-questions/writing-arcpy-getmessages-to-a-text-file/m-p/171419#M13178</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It works... use it... if there was more than 1 message you could get fancy with string formatting&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;#s = str(arcpy.GetMessages())&lt;/SPAN&gt;

messages &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'two'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'three'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&amp;nbsp; &lt;SPAN class="comment token"&gt;# a substitute for your s... no need to convert to str&lt;/SPAN&gt;

s &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Script messages returned...\n"&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"\n{}"&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;*&lt;/SPAN&gt;len&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;messages&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;*&lt;/SPAN&gt;messages&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;s&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# print or save... this is the return&lt;/SPAN&gt;

Script messages returned&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;

&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;
two
three
&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:52:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-arcpy-getmessages-to-a-text-file/m-p/171419#M13178</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T08:52:58Z</dc:date>
    </item>
    <item>
      <title>Re: writing arcpy.GetMessages() to a text file?</title>
      <link>https://community.esri.com/t5/python-questions/writing-arcpy-getmessages-to-a-text-file/m-p/171420#M13179</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Dan. I do have multiple messages (potentially hundreds)....but my three lines of code seems to handle this. Every message ends up on its own line in the text file. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So you know how much of a noob I am at Python....I'm not even sure what you're doing with the curly-brackets or asterisk. Will do some edumacating and see what that's about. Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Jul 2018 22:24:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-arcpy-getmessages-to-a-text-file/m-p/171420#M13179</guid>
      <dc:creator>KeithD1</dc:creator>
      <dc:date>2018-07-05T22:24:09Z</dc:date>
    </item>
    <item>
      <title>Re: writing arcpy.GetMessages() to a text file?</title>
      <link>https://community.esri.com/t5/python-questions/writing-arcpy-getmessages-to-a-text-file/m-p/171421#M13180</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Edumacation!... my job is done then&amp;nbsp;&lt;A href="https://docs.python.org/3/library/string.html#format-specification-mini-language"&gt;https://docs.python.org/3/library/string.html#format-specification-mini-language&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;some of my blog posts on the topic&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A _jive_internal="true" href="https://community.esri.com/blogs/dan_patterson/2016/03/01/basic-fancy-formats"&gt;https://community.esri.com/blogs/dan_patterson/2016/03/01/basic-fancy-formats&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A _jive_internal="true" href="https://community.esri.com/blogs/dan_patterson/2016/03/01/fancy-fancy-formatting"&gt;https://community.esri.com/blogs/dan_patterson/2016/03/01/fancy-fancy-formatting&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;a more useful application of curly brackets&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Jul 2018 22:53:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-arcpy-getmessages-to-a-text-file/m-p/171421#M13180</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2018-07-05T22:53:32Z</dc:date>
    </item>
    <item>
      <title>Re: writing arcpy.GetMessages() to a text file?</title>
      <link>https://community.esri.com/t5/python-questions/writing-arcpy-getmessages-to-a-text-file/m-p/171422#M13181</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A slightly more compact, and more Pythonic way, would be to use a Python &lt;SPAN style="font-family: courier new, courier, monospace;"&gt;with&lt;/SPAN&gt; statement:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;with&lt;/SPAN&gt; open&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;resultLogFile&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"a"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; f&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; f&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;write&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;GetMessages&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:53:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-arcpy-getmessages-to-a-text-file/m-p/171422#M13181</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-11T08:53:01Z</dc:date>
    </item>
    <item>
      <title>Re: writing arcpy.GetMessages() to a text file?</title>
      <link>https://community.esri.com/t5/python-questions/writing-arcpy-getmessages-to-a-text-file/m-p/171423#M13182</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I like that... a lot!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Jul 2018 23:40:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-arcpy-getmessages-to-a-text-file/m-p/171423#M13182</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2018-07-05T23:40:17Z</dc:date>
    </item>
    <item>
      <title>Re: writing arcpy.GetMessages() to a text file?</title>
      <link>https://community.esri.com/t5/python-questions/writing-arcpy-getmessages-to-a-text-file/m-p/171424#M13183</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;although starred expressions and assignment expressions are as simple as you can get &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.python.org/3/reference/simple_stmts.html#expression-statements"&gt;https://docs.python.org/3/reference/simple_stmts.html#expression-statements&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jul 2018 01:11:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-arcpy-getmessages-to-a-text-file/m-p/171424#M13183</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2018-07-06T01:11:18Z</dc:date>
    </item>
    <item>
      <title>Re: writing arcpy.GetMessages() to a text file?</title>
      <link>https://community.esri.com/t5/python-questions/writing-arcpy-getmessages-to-a-text-file/m-p/1002641#M59082</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do you script out the location of the txt file / is there more to the script than what has been shared on this thread.&lt;/P&gt;&lt;P&gt;I am wanting to extract the Message from geocoding results and log them in a txt file with the corresponding txt file that is created when you "Save A Python Script", since doing that does not bring along the messages.&lt;/P&gt;&lt;P&gt;In this thread it is said to manually copy and paste the messages to a txt file directly from the GP History log pane in Pro&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/modelbuilder-questions/model-builder-can-i-write-text-from-results-window-outputs-to/td-p/857924" target="_self"&gt;https://community.esri.com/t5/modelbuilder-questions/model-builder-can-i-write-text-from-results-window-outputs-to/td-p/857924&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 797px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/475iEEDA8A9852EFD008/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;It would be nice to be able to run weekly geocoder rebuilds and geocode our address data against our actual and theoretical address ranges along with a fishbone analysis to track and log the progress and accuracy of our address data, especially since this data is shared with our communications people.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Wed, 18 Nov 2020 18:40:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/writing-arcpy-getmessages-to-a-text-file/m-p/1002641#M59082</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2020-11-18T18:40:07Z</dc:date>
    </item>
  </channel>
</rss>

