<?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: Export model to Python and local variables are still hard-coded in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/export-model-to-python-and-local-variables-are/m-p/377957#M29801</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would always check scripts exported from modelbuilder or from a geoprocessing result, they are usually a good starter for you to work with, but can usually be simplified a good deal.&amp;nbsp; I am curious which other tools you have seen similar results, usually if the file path or file name is a parameter of some sort it it gets converted to a variable, otherwise I suppose it would hard code it. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I always just find it convenient that you can export a gp result or model to script, its a simple way to get a script started that you will need to build into something more complicated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 26 Aug 2014 19:12:24 GMT</pubDate>
    <dc:creator>IanMurray</dc:creator>
    <dc:date>2014-08-26T19:12:24Z</dc:date>
    <item>
      <title>Export model to Python and local variables are still hard-coded</title>
      <link>https://community.esri.com/t5/python-questions/export-model-to-python-and-local-variables-are/m-p/377954#M29798</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is there a way to export a model to a Python script and avoid the local variable paths from being hard-coded? In the sample code below, you can see the export took the effort to make the beginning parameters into variables but the rest of the script still has the same path hard-coded. What's up with that?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14090784579676587 jive_text_macro" jivemacro_uid="_14090784579676587"&gt;
&lt;P&gt;# -*- coding: utf-8 -*-&lt;/P&gt;
&lt;P&gt;# ---------------------------------------------------------------------------&lt;/P&gt;
&lt;P&gt;# deletethis.py&lt;/P&gt;
&lt;P&gt;# Created on: 2014-08-26 11:36:22.00000&lt;/P&gt;
&lt;P&gt;#&amp;nbsp;&amp;nbsp; (generated by ArcGIS/ModelBuilder)&lt;/P&gt;
&lt;P&gt;# Description: &lt;/P&gt;
&lt;P&gt;# ---------------------------------------------------------------------------&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Import arcpy module&lt;/P&gt;
&lt;P&gt;import arcpy&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Local variables:&lt;/P&gt;
&lt;P&gt;TEMP_Point = "N:\\TechTemp\\BlakeT\\Work\\TEMP.gdb\\TEMP_Point"&lt;/P&gt;
&lt;P&gt;TEMP_gdb = "N:\\TechTemp\\BlakeT\\Work\\TEMP.gdb"&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Process: Table to Table&lt;/P&gt;
&lt;P&gt;arcpy.TableToTable_conversion(TEMP_Point, TEMP_gdb, "TEMP_Pont_Output", "", "Note1 \"Note1\" true true false 50 Text 0 0 ,First,#,N:\\TechTemp\\BlakeT\\Work\\TEMP.gdb\\TEMP_Point,Note1,-1,-1;Note2 \"Note2\" true true false 50 Text 0 0 ,First,#,N:\\TechTemp\\BlakeT\\Work\\TEMP.gdb\\TEMP_Point,Note2,-1,-1", "")&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Aug 2014 18:41:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-model-to-python-and-local-variables-are/m-p/377954#M29798</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2014-08-26T18:41:56Z</dc:date>
    </item>
    <item>
      <title>Re: Export model to Python and local variables are still hard-coded</title>
      <link>https://community.esri.com/t5/python-questions/export-model-to-python-and-local-variables-are/m-p/377955#M29799</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Blake,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The only place it hard-coded any values was during the optional field mapping, which unless you are using you could remove all the optional parameters out, and only work with the 3 required parameters.&amp;nbsp; I don't believe there is anyway to stop this from happening, but if you are not using the optional parameters, simply removing them after exporting the script.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Aug 2014 18:52:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-model-to-python-and-local-variables-are/m-p/377955#M29799</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2014-08-26T18:52:16Z</dc:date>
    </item>
    <item>
      <title>Re: Export model to Python and local variables are still hard-coded</title>
      <link>https://community.esri.com/t5/python-questions/export-model-to-python-and-local-variables-are/m-p/377956#M29800</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ah, you are correct. I removed all the field mapping junk from the Python script and it went just fine. I've noticed this same issue on some other tools as well (not just Table to Table). Is this just one of those things everyone knows about and just works around by manually editing the Python script code?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Aug 2014 19:07:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-model-to-python-and-local-variables-are/m-p/377956#M29800</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2014-08-26T19:07:17Z</dc:date>
    </item>
    <item>
      <title>Re: Export model to Python and local variables are still hard-coded</title>
      <link>https://community.esri.com/t5/python-questions/export-model-to-python-and-local-variables-are/m-p/377957#M29801</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would always check scripts exported from modelbuilder or from a geoprocessing result, they are usually a good starter for you to work with, but can usually be simplified a good deal.&amp;nbsp; I am curious which other tools you have seen similar results, usually if the file path or file name is a parameter of some sort it it gets converted to a variable, otherwise I suppose it would hard code it. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I always just find it convenient that you can export a gp result or model to script, its a simple way to get a script started that you will need to build into something more complicated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Aug 2014 19:12:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-model-to-python-and-local-variables-are/m-p/377957#M29801</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2014-08-26T19:12:24Z</dc:date>
    </item>
    <item>
      <title>Re: Export model to Python and local variables are still hard-coded</title>
      <link>https://community.esri.com/t5/python-questions/export-model-to-python-and-local-variables-are/m-p/377958#M29802</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm on ArcGIS 10.2.2. I've also seen this in TableToGeodatabase (multiple), FeatureClassToFeatureClass, Append, and Merge. There's probably more but those are the ones I use most frequently.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your help Ian!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Aug 2014 19:23:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-model-to-python-and-local-variables-are/m-p/377958#M29802</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2014-08-26T19:23:47Z</dc:date>
    </item>
    <item>
      <title>Re: Export model to Python and local variables are still hard-coded</title>
      <link>https://community.esri.com/t5/python-questions/export-model-to-python-and-local-variables-are/m-p/377959#M29803</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;All of those but Table to Geodatabase use field mapping, so thats not so surprising.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Aug 2014 19:32:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-model-to-python-and-local-variables-are/m-p/377959#M29803</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2014-08-26T19:32:42Z</dc:date>
    </item>
    <item>
      <title>Re: Export model to Python and local variables are still hard-coded</title>
      <link>https://community.esri.com/t5/python-questions/export-model-to-python-and-local-variables-are/m-p/377960#M29804</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yeah, the table to geodatabase was extra weird because it made local variables but still hard-coded them in the parameters of the script. It didn't even call the variables!&lt;/P&gt;&lt;P&gt;EDIT: I see it did use the variable for the output parameter but the input tables parameter has them all hard-coded even though it made variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14090821032717491 jive_text_macro" jivemacro_uid="_14090821032717491"&gt;
&lt;P&gt;# -*- coding: utf-8 -*-&lt;/P&gt;
&lt;P&gt;# ---------------------------------------------------------------------------&lt;/P&gt;
&lt;P&gt;# TableToGeodatabaseMultiple.py&lt;/P&gt;
&lt;P&gt;# Created on: 2014-08-26 12:40:36.00000&lt;/P&gt;
&lt;P&gt;#&amp;nbsp;&amp;nbsp; (generated by ArcGIS/ModelBuilder)&lt;/P&gt;
&lt;P&gt;# Description: &lt;/P&gt;
&lt;P&gt;# ---------------------------------------------------------------------------&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Import arcpy module&lt;/P&gt;
&lt;P&gt;import arcpy&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Local variables:&lt;/P&gt;
&lt;P&gt;PD_GroupHome_Status = "N:\\TechTemp\\BlakeT\\Work\\GroupHome_Helpdesk43929\\GroupHome.gdb\\PD_GroupHome_Status"&lt;/P&gt;
&lt;P&gt;PD_GroupHome_Type = "N:\\TechTemp\\BlakeT\\Work\\GroupHome_Helpdesk43929\\GroupHome.gdb\\PD_GroupHome_Type"&lt;/P&gt;
&lt;P&gt;TEMP_gdb = "N:\\TechTemp\\BlakeT\\Work\\TEMP.gdb"&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Process: Table to Geodatabase (multiple)&lt;/P&gt;
&lt;P&gt;arcpy.TableToGeodatabase_conversion("N:\\TechTemp\\BlakeT\\Work\\GroupHome_Helpdesk43929\\GroupHome.gdb\\PD_GroupHome_Status;N:\\TechTemp\\BlakeT\\Work\\GroupHome_Helpdesk43929\\GroupHome.gdb\\PD_GroupHome_Type", TEMP_gdb)&lt;/P&gt;

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Aug 2014 19:37:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-model-to-python-and-local-variables-are/m-p/377960#M29804</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2014-08-26T19:37:34Z</dc:date>
    </item>
    <item>
      <title>Re: Export model to Python and local variables are still hard-coded</title>
      <link>https://community.esri.com/t5/python-questions/export-model-to-python-and-local-variables-are/m-p/377961#M29805</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thats the only one which is a script tool, which might have something to do with it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Aug 2014 19:42:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-model-to-python-and-local-variables-are/m-p/377961#M29805</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2014-08-26T19:42:00Z</dc:date>
    </item>
  </channel>
</rss>

