<?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: Set gp.workspace with a Variable Read in from a Text File in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/set-gp-workspace-with-a-variable-read-in-from-a/m-p/570109#M44709</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If you are running this from within an ArcMap/Catalog session you can also create a tool script dialog box and attach your script to it to get the input that way and the dialog will ensure it is a workspace as well.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 23 Mar 2012 00:31:44 GMT</pubDate>
    <dc:creator>StephenBarrow</dc:creator>
    <dc:date>2012-03-23T00:31:44Z</dc:date>
    <item>
      <title>Set gp.workspace with a Variable Read in from a Text File</title>
      <link>https://community.esri.com/t5/python-questions/set-gp-workspace-with-a-variable-read-in-from-a/m-p/570107#M44707</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;To All Python Users:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In ArcGIS v9.3.1 I want to be able to set certain variables such as the gp.workspace from a configuration file outside the python script so it is not hard-coded in the script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I was able to read in text for other variables I needed to set but it did not work with gp.workspace as I received the following error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "G:\deptdata\GIS\GIS_Services\User\server_Scripts\01_Data_Read_Config.py", line 37, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.workspace = "'" + source + "'"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;RuntimeError: NotInitialized&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The code to set the variable source is as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;vars = myfile.read().rstrip().split(",")&amp;nbsp; connSDE = vars[0] EOC_source = vars[1]&amp;nbsp; gp.workspace = "'" + EOC_source + "'"&amp;nbsp; (I have tried gp.workspace = """ + EOC_source + """ as well as gp.workspace = EOC_source &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Can gp.workspace be set with a variable?&amp;nbsp; If so, what am I doing wrong with the syntax?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help or hints regarding this issue are greatly appreciated.&amp;nbsp; Thanks.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Mar 2012 13:18:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/set-gp-workspace-with-a-variable-read-in-from-a/m-p/570107#M44707</guid>
      <dc:creator>MichaelVolz</dc:creator>
      <dc:date>2012-03-22T13:18:22Z</dc:date>
    </item>
    <item>
      <title>Re: Set gp.workspace with a Variable Read in from a Text File</title>
      <link>https://community.esri.com/t5/python-questions/set-gp-workspace-with-a-variable-read-in-from-a/m-p/570108#M44708</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Michael, have you tried using print or arcpy.AddMessage to ensure the variable is coming through as expected? You can also do type(). If you are running as a script tool:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;gp.AddMessage(EOC_source) gd.AddMessage(str(type(EOC_source))&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;SPAN&gt;or from the command line:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;print EOC_source print type(EOC_source)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;SPAN&gt;Either of these should produce (for example):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;C:/Datastore/2006/Forestry/&lt;BR /&gt;&amp;lt;type 'str'&amp;gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EOC_source &lt;/SPAN&gt;&lt;STRONG style="font-style: italic;"&gt;should&lt;/STRONG&gt;&lt;SPAN&gt; be coming through as a string, which means just writing:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;gp.workspace = EOC_source&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;SPAN&gt;should work.... Although it is possible that the syntax for 9.3 is different.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Mar 2012 20:17:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/set-gp-workspace-with-a-variable-read-in-from-a/m-p/570108#M44708</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2012-03-22T20:17:46Z</dc:date>
    </item>
    <item>
      <title>Re: Set gp.workspace with a Variable Read in from a Text File</title>
      <link>https://community.esri.com/t5/python-questions/set-gp-workspace-with-a-variable-read-in-from-a/m-p/570109#M44709</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If you are running this from within an ArcMap/Catalog session you can also create a tool script dialog box and attach your script to it to get the input that way and the dialog will ensure it is a workspace as well.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Mar 2012 00:31:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/set-gp-workspace-with-a-variable-read-in-from-a/m-p/570109#M44709</guid>
      <dc:creator>StephenBarrow</dc:creator>
      <dc:date>2012-03-23T00:31:44Z</dc:date>
    </item>
    <item>
      <title>Re: Set gp.workspace with a Variable Read in from a Text File</title>
      <link>https://community.esri.com/t5/python-questions/set-gp-workspace-with-a-variable-read-in-from-a/m-p/570110#M44710</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you for the reply Stacy.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I was using python syntax that is compatible with ArcGIS v10, but I was mistakenly running the code on an ArcGIS v9.3.1.&amp;nbsp; Once I ran the code on an ArcGIS v10 machine it worked fine.&amp;nbsp; This type of stuff happens as I am working in dual environments as my organization works on upgrading GIS software and GIS dependent applications.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Mar 2012 17:14:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/set-gp-workspace-with-a-variable-read-in-from-a/m-p/570110#M44710</guid>
      <dc:creator>MichaelVolz</dc:creator>
      <dc:date>2012-03-23T17:14:02Z</dc:date>
    </item>
  </channel>
</rss>

