<?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: Interesting requirement in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/interesting-requirement/m-p/580825#M45572</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Here's what I've come up with:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

origapp = sys.executable
if "ArcMap" in origapp:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("...The python script is being executed from ArcGIS/Toolbox")
elif "Pythonwin.exe" in origapp:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "...The python script is being executed from PythonWin"

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 00:58:52 GMT</pubDate>
    <dc:creator>JamesCrandall</dc:creator>
    <dc:date>2021-12-12T00:58:52Z</dc:date>
    <item>
      <title>Interesting requirement</title>
      <link>https://community.esri.com/t5/python-questions/interesting-requirement/m-p/580821#M45568</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have an interesting requirement and looking for comments...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In order to reduce duplication of modules/def's in our codebase, I need a way to determine WHERE something is being executed from.&amp;nbsp; That is, our requirement is users will have the ability to execute a process from an ArcToolbox OR from a command line (both with args/params).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there a way to detect/test if it is being executed from Command line or from an ArcToolbox?&amp;nbsp; The reason is that I will need to set variables in the script with the command line args or toolbox (GetParameter).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;j&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Oct 2013 17:50:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/interesting-requirement/m-p/580821#M45568</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2013-10-01T17:50:16Z</dc:date>
    </item>
    <item>
      <title>Re: Interesting requirement</title>
      <link>https://community.esri.com/t5/python-questions/interesting-requirement/m-p/580822#M45569</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think I can use sys.stdout to do this...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This code, executed from PythonWin prints "pwin.framework.interact.InteractiveView at..."&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

value = sys.stdout
print value

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This code, executed from an ArcToolbox script with the .py as source prints "geoprocessing sys.stdout object object at..."&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

value = sys.stdout
arcpy.AddMessage(str(value))

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any other ideas are appreciated!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:58:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/interesting-requirement/m-p/580822#M45569</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-12T00:58:50Z</dc:date>
    </item>
    <item>
      <title>Re: Interesting requirement</title>
      <link>https://community.esri.com/t5/python-questions/interesting-requirement/m-p/580823#M45570</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;A class="jive-link-external-small" href="http://forums.arcgis.com/threads/93091-Detect-which-ArcGIS-Application-script-is-executing-from" rel="nofollow" target="_blank"&gt;&lt;SPAN style="font-family:Courier New;"&gt;sys.executable&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Oct 2013 18:25:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/interesting-requirement/m-p/580823#M45570</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2013-10-01T18:25:59Z</dc:date>
    </item>
    <item>
      <title>Re: Interesting requirement</title>
      <link>https://community.esri.com/t5/python-questions/interesting-requirement/m-p/580824#M45571</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;A href="http://forums.arcgis.com/threads/93091-Detect-which-ArcGIS-Application-script-is-executing-from"&gt;&lt;SPAN style="font-family:Courier New;"&gt;sys.executable&lt;/SPAN&gt;&lt;/A&gt;.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;That'll work too!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks Jason.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Oct 2013 18:42:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/interesting-requirement/m-p/580824#M45571</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2013-10-01T18:42:29Z</dc:date>
    </item>
    <item>
      <title>Re: Interesting requirement</title>
      <link>https://community.esri.com/t5/python-questions/interesting-requirement/m-p/580825#M45572</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Here's what I've come up with:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

origapp = sys.executable
if "ArcMap" in origapp:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("...The python script is being executed from ArcGIS/Toolbox")
elif "Pythonwin.exe" in origapp:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "...The python script is being executed from PythonWin"

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:58:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/interesting-requirement/m-p/580825#M45572</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-12T00:58:52Z</dc:date>
    </item>
  </channel>
</rss>

