<?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: working with Arcpy script and multiple imbricated python functions in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/working-with-arcpy-script-and-multiple-imbricated/m-p/1493638#M27316</link>
    <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/215600"&gt;@DanPatterson&lt;/a&gt;&amp;nbsp;for the quick answer. However, I'm not sure if this answers all my questions.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically, are you saying that the&amp;nbsp;&lt;SPAN&gt;"if__name__ ..." part is indeed what replaces the calling function part of a normal script?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;As for the EnvManager, I believe it might be an artefact from a previously builder converted to python script. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So the amended script should be something like that?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import blabla

#Functions
def function1(Table, Param)
    intermediateTable = do something with Table and Param
    print("Intermediate table created")

def function2(param1, table1, param2, table2):
    do something 1(param1, param2)
        new_param1
    do something 2(param1, param2)
        new_param2
    if param1 == "**unspecified**":
        intermediateTable = function1(table1, new_param1)
        newParam = new_param1
    elif param2 == "aaaa":
        intermediateTable = function1(table1, new_param1)
        newParam = new_param1
    else:
        intermediateTable = function1(table2, new_param2)
        newParam = new_param2

    do other stuff
    print("New param created")

def function3(param1, table1, param2, table2, param3, param4, newParam, intermediateTable): #This is where all params would be called
    create gdb
    ...
    function2(param1, table1, param2, table2)
    ...
    do something with param3, param4, newParam, intermediateTable to create finalTable
    print("Final table completed")

"""
&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;head&amp;gt;
    do something with finalTable...
&amp;lt;/head&amp;gt;
&amp;lt;/html&amp;gt;
"""

if __name__=="__main__":
    function3(sys.argv[1:])
&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 17 Jun 2024 12:02:50 GMT</pubDate>
    <dc:creator>Anne-MarieDubois</dc:creator>
    <dc:date>2024-06-17T12:02:50Z</dc:date>
    <item>
      <title>working with Arcpy script and multiple imbricated python functions</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/working-with-arcpy-script-and-multiple-imbricated/m-p/1492794#M27314</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;I'm trying to build an arcpy script with 3 layers of imbricated functions but I'm running a bit confused.&lt;/P&gt;&lt;P&gt;Here is an example of what I'm trying to achieve.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import blabla

#Functions
def function1(Table, Param)
    intermediateTable = do something with Table and Param 

def function2(param1, table1, param2, table2):
    do something 1(param1, param2)
        new_param1
    do something 2(param1, param2)
        new_param2
    if param1 == "**unspecified**":
        intermediateTable = function1(table1, new_param1)
        newParam = new_param1
    elif param2 == "aaaa":
        intermediateTable = function1(table1, new_param1)
        newParam = new_param1
    else:
        intermediateTable = function1(table2, new_param2)
        newParam = new_param2

    do other stuff

def function3(param1, table1, param2, table2, param3, param4, newParam, intermediateTable): #This is where all params would be called
    create gdb
    ...
    function2(param1, table1, param2, table2)
    ...
    do something with param3, param4, newParam, intermediateTable to create finalTable

"""
&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;head&amp;gt;
    do something with finalTable...
&amp;lt;/head&amp;gt;
&amp;lt;/html&amp;gt;
"""

if __name__=="__main__":
    #Global Environment settings
    with arcpy.EnvManager():
        function3(*argv[1:])&lt;/LI-CODE&gt;&lt;P&gt;I can't seem to making it work. What am I doing wrong?&lt;/P&gt;&lt;P&gt;But weirdly, if all my functions are built into one script (aka, no functions, just repeating the code), it does not seem to need the line to "call the function"... or is it what the "if__name__ ...etc" is for?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2024 15:59:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/working-with-arcpy-script-and-multiple-imbricated/m-p/1492794#M27314</guid>
      <dc:creator>Anne-MarieDubois</dc:creator>
      <dc:date>2024-06-14T15:59:47Z</dc:date>
    </item>
    <item>
      <title>Re: working with Arcpy script and multiple imbricated python functions</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/working-with-arcpy-script-and-multiple-imbricated/m-p/1492808#M27315</link>
      <description>&lt;P&gt;If you just run a script all the imports and functions are read and put into python's namespace..&lt;/P&gt;&lt;P&gt;when it hits line 40 python will find that __name__ does indeed == __main__&lt;/P&gt;&lt;P&gt;not sure why you need EnvManager, so I will leave that&lt;/P&gt;&lt;P&gt;and the last line is the call to function3 with a list of unspecified arguments which should be called by sys.argv (since sys.argv[0] is the name of the running script)&lt;/P&gt;&lt;P&gt;It would be useful if the functions did something or reported something (eg print statments ) or returned something (even a blank return statment)&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2024 16:36:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/working-with-arcpy-script-and-multiple-imbricated/m-p/1492808#M27315</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2024-06-14T16:36:31Z</dc:date>
    </item>
    <item>
      <title>Re: working with Arcpy script and multiple imbricated python functions</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/working-with-arcpy-script-and-multiple-imbricated/m-p/1493638#M27316</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/215600"&gt;@DanPatterson&lt;/a&gt;&amp;nbsp;for the quick answer. However, I'm not sure if this answers all my questions.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically, are you saying that the&amp;nbsp;&lt;SPAN&gt;"if__name__ ..." part is indeed what replaces the calling function part of a normal script?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;As for the EnvManager, I believe it might be an artefact from a previously builder converted to python script. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So the amended script should be something like that?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import blabla

#Functions
def function1(Table, Param)
    intermediateTable = do something with Table and Param
    print("Intermediate table created")

def function2(param1, table1, param2, table2):
    do something 1(param1, param2)
        new_param1
    do something 2(param1, param2)
        new_param2
    if param1 == "**unspecified**":
        intermediateTable = function1(table1, new_param1)
        newParam = new_param1
    elif param2 == "aaaa":
        intermediateTable = function1(table1, new_param1)
        newParam = new_param1
    else:
        intermediateTable = function1(table2, new_param2)
        newParam = new_param2

    do other stuff
    print("New param created")

def function3(param1, table1, param2, table2, param3, param4, newParam, intermediateTable): #This is where all params would be called
    create gdb
    ...
    function2(param1, table1, param2, table2)
    ...
    do something with param3, param4, newParam, intermediateTable to create finalTable
    print("Final table completed")

"""
&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;head&amp;gt;
    do something with finalTable...
&amp;lt;/head&amp;gt;
&amp;lt;/html&amp;gt;
"""

if __name__=="__main__":
    function3(sys.argv[1:])
&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2024 12:02:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/working-with-arcpy-script-and-multiple-imbricated/m-p/1493638#M27316</guid>
      <dc:creator>Anne-MarieDubois</dc:creator>
      <dc:date>2024-06-17T12:02:50Z</dc:date>
    </item>
    <item>
      <title>Re: working with Arcpy script and multiple imbricated python functions</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/working-with-arcpy-script-and-multiple-imbricated/m-p/1493973#M27317</link>
      <description>&lt;P&gt;work with something simpler until you get the hang of what you want the output to be&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# -*- coding: utf-8 -*-
"""
Created on Mon Jun 17 11:59:13 2024.

@author: dan_p
"""

import sys

script = sys.argv[0]


def f0(p0):
    """Call function 0."""
    print("f0: {}".format(p0))
    return p0 + "b"


def f1(p1):
    """Call function 1."""
    print("f1: {}".format(p1))
    return p1 + "c"


def f2(p2):
    """Call function 2."""
    print("f2: {}".format(p2))
    return p2 + "d"


def main():
    """Start the process."""
    val = "a"
    ret0 = f0(val)
    ret1 = f1(ret0)
    ret2 = f2(ret1)
    return "{} {} {}".format(ret0, ret1, ret2)


# ---- ---------------------------
# ---- Final main section
if __name__ == "__main__":
    """optional location for parameters"""
    print(f"\nRunning... {script}\n")
    final = main()
    print("final = {}".format(final))&lt;/LI-CODE&gt;&lt;P&gt;Sample run&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Running... c:\arcpro_npg\npg\tests\test.py

f0: a
f1: ab
f2: abc
final = ab abc abcd&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 17 Jun 2024 20:33:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/working-with-arcpy-script-and-multiple-imbricated/m-p/1493973#M27317</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2024-06-17T20:33:59Z</dc:date>
    </item>
  </channel>
</rss>

