<?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: Incorporate one variable into another in ArcPy Script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/incorporate-one-variable-into-another-in-arcpy/m-p/458214#M35976</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It worked! Output workspace and stats are defined elsewhere.&amp;nbsp; So the new script is shown as this instead:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;for file in arcpy.ListFiles("*.txt"):&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;loss_table&lt;/STRONG&gt; = os.path.join(output_workspace, str(file[:-4]))&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; summary = (str(&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;loss_table&lt;/STRONG&gt; + "summ"))&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.TableToGeodatabase_conversion(file, output_workspace)&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Statistics_analysis(loss_table, summary, stats, "CensusBlock")&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Thanks so much for the tip!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 12 Jun 2015 13:18:05 GMT</pubDate>
    <dc:creator>MeredithGreen</dc:creator>
    <dc:date>2015-06-12T13:18:05Z</dc:date>
    <item>
      <title>Incorporate one variable into another in ArcPy Script</title>
      <link>https://community.esri.com/t5/python-questions/incorporate-one-variable-into-another-in-arcpy/m-p/458212#M35974</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to take a bunch of text files and export them to a workspace geodatabase and then take the new tables and do a summary stats calculation and export that out as a new table that is whatever the loss table is plus &lt;EM&gt;summ &lt;/EM&gt;at the end.&amp;nbsp; Script is below.&amp;nbsp; What exactly is the best way to do this with a variable?&amp;nbsp; Any help would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for file in arcpy.ListFiles("*.txt"):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;loss_table&lt;/STRONG&gt; = os.path.join(output_workspace, str(file[:-4]))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; summary = os.path.join(output_workspace, str(&lt;STRONG&gt;loss_table&lt;/STRONG&gt; + "summ"))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.TableToGeodatabase_conversion(file, output_workspace) &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Statistics_analysis(loss_table, summary, stats, "CensusBlock")&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Jun 2015 12:44:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/incorporate-one-variable-into-another-in-arcpy/m-p/458212#M35974</guid>
      <dc:creator>MeredithGreen</dc:creator>
      <dc:date>2015-06-12T12:44:09Z</dc:date>
    </item>
    <item>
      <title>Re: Incorporate one variable into another in ArcPy Script</title>
      <link>https://community.esri.com/t5/python-questions/incorporate-one-variable-into-another-in-arcpy/m-p/458213#M35975</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Meredith, Right now, you're joining your output workspace path to the summary path twice. Try just removing the output workspace from summary. I'm assuming, of course, that you have your other variables, such as output_workspace and stats, defined in a different part of the script.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Jun 2015 12:53:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/incorporate-one-variable-into-another-in-arcpy/m-p/458213#M35975</guid>
      <dc:creator>SepheFox</dc:creator>
      <dc:date>2015-06-12T12:53:03Z</dc:date>
    </item>
    <item>
      <title>Re: Incorporate one variable into another in ArcPy Script</title>
      <link>https://community.esri.com/t5/python-questions/incorporate-one-variable-into-another-in-arcpy/m-p/458214#M35976</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It worked! Output workspace and stats are defined elsewhere.&amp;nbsp; So the new script is shown as this instead:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;for file in arcpy.ListFiles("*.txt"):&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;loss_table&lt;/STRONG&gt; = os.path.join(output_workspace, str(file[:-4]))&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; summary = (str(&lt;STRONG style="font-style: inherit; font-family: inherit;"&gt;loss_table&lt;/STRONG&gt; + "summ"))&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.TableToGeodatabase_conversion(file, output_workspace)&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Statistics_analysis(loss_table, summary, stats, "CensusBlock")&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Thanks so much for the tip!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Jun 2015 13:18:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/incorporate-one-variable-into-another-in-arcpy/m-p/458214#M35976</guid>
      <dc:creator>MeredithGreen</dc:creator>
      <dc:date>2015-06-12T13:18:05Z</dc:date>
    </item>
    <item>
      <title>Re: Incorporate one variable into another in ArcPy Script</title>
      <link>https://community.esri.com/t5/python-questions/incorporate-one-variable-into-another-in-arcpy/m-p/458215#M35977</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are very welcome. I'm just happy I could actually solve a python problem--a fairly rare event! &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Jun 2015 13:20:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/incorporate-one-variable-into-another-in-arcpy/m-p/458215#M35977</guid>
      <dc:creator>SepheFox</dc:creator>
      <dc:date>2015-06-12T13:20:31Z</dc:date>
    </item>
    <item>
      <title>Re: Incorporate one variable into another in ArcPy Script</title>
      <link>https://community.esri.com/t5/python-questions/incorporate-one-variable-into-another-in-arcpy/m-p/458216#M35978</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Meredith, here are few suggested improvements:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Use&amp;nbsp; os.path.splitext() to get the filename without the extension (safer)&lt;/P&gt;&lt;P&gt;2. Use .format() instead of appending strings (easier to read and debug)&lt;/P&gt;&lt;P&gt;3. Use CopyRows instead of TableToGeodatabase (this gives you more control over what the output is named)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for file in arcpy.ListFiles("*.txt"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; loss_table = os.path.join(output_workspace, os.path.splitext(file)[0])
&amp;nbsp;&amp;nbsp;&amp;nbsp; summary = "{}summ".format(loss_table)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyRows_management(file, loss_table)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Statistics_analysis(loss_table, summary, stats, "CensusBlock")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:23:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/incorporate-one-variable-into-another-in-arcpy/m-p/458216#M35978</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T20:23:58Z</dc:date>
    </item>
  </channel>
</rss>

