<?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 How to pass arguments to function in module? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-pass-arguments-to-function-in-module/m-p/203900#M15683</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I know there's a ton of other material here and @ SE regarding this subject, but conceptually i'm just stuck. In an effort to improve the modularity of my code, I'm trying to get better at importing existing functions into scripts. I'm stuck on successfully passing arguments captured within the script to the imported module. Ideally I just want to use the script and pass it a handful of client identifiers (arguments) and have those cascade down into several modules called up in&amp;nbsp; the script. Like: functiontest2('identifier')&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;some crude code:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;functiontest2.py&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; HarvestTable &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; HarvestTableReport
&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; sys
HarvestThing &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; sys&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;argv&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;

HarvestTableReport&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;HarvestThing&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;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;HarvestTable.py&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; numpy &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; np
&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; pandas &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; pd
&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy
    
&lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;HarvestTableReport&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;HarvestID&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    table &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"\\\\fileshare\SDE_CONNECTIONS\\LV_NEXUS.sde\\LV_NEXUS.DATAOWNER.NORTHEAST\\clientGDB.featureclass"&lt;/SPAN&gt;
    HUID &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; HarvestID
    whereClause &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;""" "LV_HARVEST_UNIT_ID" = '{0}' """&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;HUID&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    tableArray &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;TableToNumPyArray&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;table&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'SUPER_TYPE'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'STRATA'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'OS_TYPE'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'STAND_NUMB'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'SILV_PRES'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'ACRES'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; where_clause &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; whereClause&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    df &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; round&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;pd&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;DataFrame&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;tableArray&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;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    report &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; df&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;groupby&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'SUPER_TYPE'&lt;/SPAN&gt;&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;apply&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="keyword token"&gt;lambda&lt;/SPAN&gt; sub_df&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;  sub_df&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;pivot_table&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;index&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'STRATA'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'OS_TYPE'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'STAND_NUMB'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'SILV_PRES'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; values&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'ACRES'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;aggfunc&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;np&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;sum&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; margins&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token boolean"&gt;True&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;margins_name&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'TOTAL'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    &lt;SPAN class="comment token"&gt;# this is creating a new row at level(1) called grand total&lt;/SPAN&gt;
    &lt;SPAN class="comment token"&gt;# set it equal to the sum of ACRES where level(1) != 'Total' so you are not counting the  calculated totals in the total sum&lt;/SPAN&gt;
    report&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;loc&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;''&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'GRAND TOTAL'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;''&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;''&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string 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="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; report&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;report&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;index&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;get_level_values&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="operator token"&gt;!=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'TOTAL'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;sum&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&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;whereClause&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; np&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;round&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;report&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="keyword token"&gt;if&lt;/SPAN&gt; __name__ &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'__main__'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    HarvestTableReport&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;/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;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 10:07:26 GMT</pubDate>
    <dc:creator>ZacharyHart</dc:creator>
    <dc:date>2021-12-11T10:07:26Z</dc:date>
    <item>
      <title>How to pass arguments to function in module?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-pass-arguments-to-function-in-module/m-p/203900#M15683</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I know there's a ton of other material here and @ SE regarding this subject, but conceptually i'm just stuck. In an effort to improve the modularity of my code, I'm trying to get better at importing existing functions into scripts. I'm stuck on successfully passing arguments captured within the script to the imported module. Ideally I just want to use the script and pass it a handful of client identifiers (arguments) and have those cascade down into several modules called up in&amp;nbsp; the script. Like: functiontest2('identifier')&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;some crude code:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;functiontest2.py&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; HarvestTable &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; HarvestTableReport
&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; sys
HarvestThing &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; sys&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;argv&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;

HarvestTableReport&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;HarvestThing&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;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;HarvestTable.py&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; numpy &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; np
&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; pandas &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; pd
&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy
    
&lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;HarvestTableReport&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;HarvestID&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    table &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"\\\\fileshare\SDE_CONNECTIONS\\LV_NEXUS.sde\\LV_NEXUS.DATAOWNER.NORTHEAST\\clientGDB.featureclass"&lt;/SPAN&gt;
    HUID &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; HarvestID
    whereClause &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;""" "LV_HARVEST_UNIT_ID" = '{0}' """&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;HUID&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    tableArray &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;TableToNumPyArray&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;table&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'SUPER_TYPE'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'STRATA'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'OS_TYPE'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'STAND_NUMB'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'SILV_PRES'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'ACRES'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; where_clause &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; whereClause&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    df &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; round&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;pd&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;DataFrame&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;tableArray&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;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    report &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; df&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;groupby&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'SUPER_TYPE'&lt;/SPAN&gt;&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;apply&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="keyword token"&gt;lambda&lt;/SPAN&gt; sub_df&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;  sub_df&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;pivot_table&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;index&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'STRATA'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'OS_TYPE'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'STAND_NUMB'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'SILV_PRES'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; values&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'ACRES'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;aggfunc&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;np&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;sum&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; margins&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token boolean"&gt;True&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;margins_name&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'TOTAL'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    &lt;SPAN class="comment token"&gt;# this is creating a new row at level(1) called grand total&lt;/SPAN&gt;
    &lt;SPAN class="comment token"&gt;# set it equal to the sum of ACRES where level(1) != 'Total' so you are not counting the  calculated totals in the total sum&lt;/SPAN&gt;
    report&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;loc&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;''&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'GRAND TOTAL'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;''&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;''&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string 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="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; report&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;report&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;index&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;get_level_values&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="operator token"&gt;!=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'TOTAL'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;sum&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&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;whereClause&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; np&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;round&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;report&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="keyword token"&gt;if&lt;/SPAN&gt; __name__ &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'__main__'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    HarvestTableReport&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;/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;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 10:07:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-pass-arguments-to-function-in-module/m-p/203900#M15683</guid>
      <dc:creator>ZacharyHart</dc:creator>
      <dc:date>2021-12-11T10:07:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass arguments to function in module?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-pass-arguments-to-function-in-module/m-p/203901#M15684</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;line 5, first script... you passed to the imported function, and it tried to return something, but you didn't do anything with it&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;i_m_Back = HarvestTableReport(HarvestThing) # ---- returned from your imported

print("Returned to you {}".format(i_m_Back))&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;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:07:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-pass-arguments-to-function-in-module/m-p/203901#M15684</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T10:07:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass arguments to function in module?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-pass-arguments-to-function-in-module/m-p/203902#M15685</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So what errors or unexpected behaviors are you getting?&amp;nbsp; If errors, please post specific errors with traceback.&amp;nbsp; If unexpected results, please post what you expect and what you are actually getting.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 May 2019 17:51:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-pass-arguments-to-function-in-module/m-p/203902#M15685</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2019-05-29T17:51:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass arguments to function in module?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-pass-arguments-to-function-in-module/m-p/203903#M15686</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've had so many&amp;nbsp; different tweaks to this it's been hard to keep track (kinda banging my head against the wall here). In the current permutation shown above if I attempt to import functiontest2 into the python window in Pro I receive the following error:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;Traceback &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;most recent call last&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
  File &lt;SPAN class="string token"&gt;"&amp;lt;string&amp;gt;"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; line &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt;module&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt;
  File &lt;SPAN class="string token"&gt;"\\fileshare\SCRIPTS\functiontest2.py"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; line &lt;SPAN class="number token"&gt;3&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt;module&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt;
    HarvestThing &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; sys&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;argv&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;
IndexError&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; list index out of range&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 10:07:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-pass-arguments-to-function-in-module/m-p/203903#M15686</guid>
      <dc:creator>ZacharyHart</dc:creator>
      <dc:date>2021-12-11T10:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass arguments to function in module?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-pass-arguments-to-function-in-module/m-p/203904#M15687</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The line&lt;/P&gt;&lt;PRE class=""&gt;&lt;CODE&gt;HarvestThing &lt;SPAN class=""&gt;=&lt;/SPAN&gt; sys&lt;SPAN class=""&gt;.&lt;/SPAN&gt;argv&lt;SPAN class=""&gt;[&lt;/SPAN&gt;&lt;SPAN class=""&gt;1&lt;/SPAN&gt;&lt;SPAN class=""&gt;]&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;is saying to take the first command line argument and pass it to HarvestThing.&amp;nbsp; Since you are importing the module and not calling it from the command line with arguments, you are getting an IndexError.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 May 2019 19:07:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-pass-arguments-to-function-in-module/m-p/203904#M15687</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2019-05-29T19:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass arguments to function in module?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-pass-arguments-to-function-in-module/m-p/203905#M15688</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I understand it correctly, you want to call a script from another, passing variables set up in the first script?&amp;nbsp; If so, here is the basic template with which to do so.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;# -*- coding: utf-8 -*-&lt;/SPAN&gt;
&lt;SPAN class="string token"&gt;"""
Created on Thu May 16 14:20:43 2019
@author: JBorgione
save  this as script1.py
"""&lt;/SPAN&gt;
var1 &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'A'&lt;/SPAN&gt;
var2 &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'B'&lt;/SPAN&gt;
var3 &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'C'&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; Script2‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&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;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;# -*- coding: utf-8 -*-&lt;/SPAN&gt;
&lt;SPAN class="string token"&gt;"""
Created on Thu May 16 14:31:01 2019
@author: JBorgione
script2.py  is called from script1.py
"""&lt;/SPAN&gt; 
&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; __main__ &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;*&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;main&lt;/SPAN&gt;&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="keyword token"&gt;print&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;var3&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;var2&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;var1&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; 

&lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; __name__ &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'Script2'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; 
    main&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;/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;P&gt;It's my understanding that when you call a&amp;nbsp;second script from a first script, __name__ = main in the&amp;nbsp;&lt;EM&gt;first script&lt;/EM&gt; but not in the second script:&amp;nbsp; __name__ = the script name itself (sans .py extension) and both of them need to be in the same directory.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;See a post of mine &lt;A _jive_internal="true" href="https://community.esri.com/thread/231888-calling-a-python-script-from-another-python-script" target="_blank"&gt;earlier this spring &lt;/A&gt;which directs you &lt;A href="https://docs.python.org/3/library/__main__.html" rel="nofollow noopener noreferrer" target="_blank"&gt;to this site&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:07:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-pass-arguments-to-function-in-module/m-p/203905#M15688</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-12-11T10:07:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass arguments to function in module?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-pass-arguments-to-function-in-module/m-p/203906#M15689</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;ok, that makes way more sense and I had success using the python cmd prompt and supplying an arrangement. thanks so much!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So is there a way to run a script from the interactive python window, or is my solution more like creating a master module that just calls up a bunch of my other single-purpose modules?&amp;nbsp; Let me try to explain what I'm hoping to achieve. Often while working along in Pro (although I could be doing the same in Jupyter Lab I guess) I want to pull some info for a given client or property. So each module might have a single function that generates a report. Rather than run each module, I want to run all of them in one script/master module. The only argument that needs to be passed to each module is like a client identifier so this should be pretty straightforward. I'd prefer to not have to jump out to the python command prompt but also don't want the overhead of rolling these up into a script tool in a Pro toolbox.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 May 2019 19:26:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-pass-arguments-to-function-in-module/m-p/203906#M15689</guid>
      <dc:creator>ZacharyHart</dc:creator>
      <dc:date>2019-05-29T19:26:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass arguments to function in module?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-pass-arguments-to-function-in-module/m-p/203907#M15690</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;See if this helps:&amp;nbsp; &lt;A class="link-titled" href="https://stackoverflow.com/questions/436198/what-is-an-alternative-to-execfile-in-python-3" title="https://stackoverflow.com/questions/436198/what-is-an-alternative-to-execfile-in-python-3"&gt;What is an alternative to execfile in Python 3? - Stack Overflow&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 May 2019 21:33:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-pass-arguments-to-function-in-module/m-p/203907#M15690</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2019-05-29T21:33:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass arguments to function in module?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-pass-arguments-to-function-in-module/m-p/203908#M15691</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are basically there and its looking good!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Im probably using incorrect concepts for advanced/correct coding, but I like to keep it simpler!&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What you have basically created in your file&amp;nbsp;&lt;SPAN style="border: 0px; font-weight: bold;"&gt;&lt;STRONG&gt;functiontest2.py&amp;nbsp; &amp;nbsp;&lt;/STRONG&gt;&lt;/SPAN&gt;is what I like to call an interface or GUI.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would rename this file:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;&lt;SPAN style="border: 0px; font-weight: bold;"&gt;&lt;STRONG&gt;harvest_report_commandline.py&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;"&gt;from&lt;/SPAN&gt; HarvestTable &lt;SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;"&gt;import&lt;/SPAN&gt; HarvestTableReport
&lt;SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;"&gt;import&lt;/SPAN&gt; sys
HarvestThing &lt;SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;"&gt;=&lt;/SPAN&gt; sys&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;.&lt;/SPAN&gt;argv&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;[&lt;/SPAN&gt;&lt;SPAN class="" style="color: #990000; border: 0px; font-weight: inherit;"&gt;1&lt;/SPAN&gt;&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;]&lt;/SPAN&gt;

HarvestTableReport&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;(&lt;/SPAN&gt;HarvestThing&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Now to run this, you run it from cmd as you are probably familiar, passing in the sys argument.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Often, I would then make another interface/gui file, so that I can easily test it inside an IDE. Something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="background-color: #ffffff; border: 0px;"&gt;&lt;SPAN style="border: 0px; font-weight: bold;"&gt;&lt;STRONG&gt;harvest_report_python.py&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;"&gt;from&lt;/SPAN&gt; HarvestTable &lt;SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit;"&gt;import&lt;/SPAN&gt; HarvestTableReport

HarvestThing &lt;SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit;"&gt;=&lt;/SPAN&gt; 'MY ID'
HarvestTableReport&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;(&lt;/SPAN&gt;HarvestThing&lt;SPAN class="" style="color: #999999; border: 0px; font-weight: inherit;"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Further down the line, I would also make a .tbx file, so it works inside arcmap as a toolbox! Something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="border: 0px; font-weight: bold;"&gt;&lt;STRONG&gt;harvest_report_ArcTool.py&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;class harvestArcToolGUI&lt;/SPAN&gt;(object):&lt;/PRE&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #808080;"&gt;    &lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;def &lt;/SPAN&gt;&lt;SPAN style="color: #b200b2;"&gt;__init__&lt;/SPAN&gt;(&lt;SPAN style="color: #94558d;"&gt;self&lt;/SPAN&gt;):
&lt;SPAN style="color: #808080;"&gt;        &lt;/SPAN&gt;&lt;SPAN style="color: #94558d;"&gt;self&lt;/SPAN&gt;.label = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'Harvest Report'
&lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-weight: bold;"&gt;        &lt;/SPAN&gt;&lt;SPAN style="color: #94558d;"&gt;self&lt;/SPAN&gt;.description = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'Get your report here!'
&lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-weight: bold;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #008000; font-weight: bold;"&gt;        &lt;/SPAN&gt;&lt;SPAN style="color: #94558d;"&gt;self&lt;/SPAN&gt;.parameters = [
            parameter(&lt;SPAN style="color: #008000; font-weight: bold;"&gt;'Harvest ID'&lt;/SPAN&gt;, &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'HarvestID'&lt;/SPAN&gt;, &lt;SPAN style="color: #008000; font-weight: bold;"&gt;'String'&lt;/SPAN&gt;),
        ]

    &lt;SPAN style="color: #000080; font-weight: bold;"&gt;def &lt;/SPAN&gt;execute(&lt;SPAN style="color: #94558d;"&gt;self&lt;/SPAN&gt;, parameters, &lt;SPAN style="color: #808080;"&gt;messages&lt;/SPAN&gt;):
        &lt;SPAN style="color: #808080;"&gt;'''
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;        Reference the business logic captured in your object defined
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;        separately in the module, preferably above.
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;        '''
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;        &lt;/SPAN&gt;inHarvestID = parameters[&lt;SPAN style="color: #0000ff;"&gt;0&lt;/SPAN&gt;].value

        &lt;SPAN style="color: #808080;"&gt;###Tool Logic
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;        &lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;execTool &lt;/SPAN&gt;= HarvestTable.HarvestTableReport (inHarvestID)

        &lt;SPAN style="color: #000080; font-weight: bold;"&gt;return







&lt;SPAN style="color: #3d3d3d; font-weight: 400;"&gt;Now, if you make changes to the orginal HarvestTable.py,    all the other interfaces will be running the updated code.&lt;/SPAN&gt;
&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:07:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-pass-arguments-to-function-in-module/m-p/203908#M15691</guid>
      <dc:creator>LukeWebb</dc:creator>
      <dc:date>2021-12-11T10:07:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass arguments to function in module?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-pass-arguments-to-function-in-module/m-p/203909#M15692</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Got pulled back to project work. This is all very helpful. As I start to wrap my head around this more I'm understanding a bit better the need for modularity and organization...it's just applying that which is still the challenge for me.&lt;/P&gt;&lt;P&gt;Based on everything I've read in this thread, so far it seems like what will benefit me the most in this situation is to organize several related functions into one module. I can then call them up as needed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks so much to everyone!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EDIT: I recently saw this article in my inbox regarding &lt;A href="https://codeburst.io/building-beautiful-command-line-interfaces-with-python-26c7e1bb54df"&gt;building command line interfaces with Python&lt;/A&gt; if anyone is interested.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Jun 2019 12:49:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-pass-arguments-to-function-in-module/m-p/203909#M15692</guid>
      <dc:creator>ZacharyHart</dc:creator>
      <dc:date>2019-06-04T12:49:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass arguments to function in module?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-pass-arguments-to-function-in-module/m-p/203910#M15693</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;It's my understanding that when you call a&amp;nbsp;second script from a first script, __name__ = main in the&amp;nbsp;&lt;EM&gt;first script&lt;/EM&gt; but not in the second script:&amp;nbsp; __name__ = the script name itself (sans .py extension) and both of them need to be in the same directory.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;This right here is something I really need to get my head around! I keep getting confused on this. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Jun 2019 12:51:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-pass-arguments-to-function-in-module/m-p/203910#M15693</guid>
      <dc:creator>ZacharyHart</dc:creator>
      <dc:date>2019-06-04T12:51:22Z</dc:date>
    </item>
  </channel>
</rss>

