<?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: How to import module into python toolbox in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-import-module-into-python-toolbox/m-p/1668800#M74947</link>
    <description>&lt;P&gt;I've got a simple framework that solves this here: &lt;A href="https://github.com/hwelch-fle/pytframe2" target="_blank" rel="noopener"&gt;https://github.com/hwelch-fle/pytframe2&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This method also makes sure that submodules are refreshed when the toolbox is refreshed, since by default the imported modules aren't reloaded until the interpreter is restarted (reboot ArcPro). This definitely makes it easier to develop a tool since you just refresh the toolbox and the new code is loaded in instantly as long as it's part of that reload chain.&lt;/P&gt;&lt;P&gt;I'm trying to add a lot of that functionality into a more holistic library under &lt;A href="https://github.com/hwelch-fle/arcpie" target="_blank" rel="noopener"&gt;https://github.com/hwelch-fle/arcpie&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another note, all class methods in Python require a self argument since calling a method on an object passes self as arg0 even with no arguments.&lt;/P&gt;</description>
    <pubDate>Wed, 26 Nov 2025 15:44:14 GMT</pubDate>
    <dc:creator>HaydenWelch</dc:creator>
    <dc:date>2025-11-26T15:44:14Z</dc:date>
    <item>
      <title>How to import module into python toolbox</title>
      <link>https://community.esri.com/t5/python-questions/how-to-import-module-into-python-toolbox/m-p/1666783#M74918</link>
      <description>&lt;P&gt;I have a very basic module I used to try and simply import it into a python tool box. The point would be run a useful application like this.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried from the same folder together&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;toolbox.pyt

# this is same folder as the toolbox
same_folder =  os.path.dirname(os.path.realpath(__file__))

if same_folder not in sys.path:
    sys.path.append(same_folder)​&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And from an different folder, just in case it cannot be in the same folder (or vv).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;toolbox.pyt

# this is diff folder than toolbox
same_folder =  "C:\some\folder\"

sys.path.append(same_folder)​&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The import resolves, but calling the func always breaks tool. These are the things I tried (with only one func at a time named test_method):&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;test_class.puy
class TestClass:
    @staticmethod
     # 1 - return this to getParameterInfo and return as [TestClass.test_method(arcpy)]
    def test_method(arcpy_instance):
         param0 = arcpy_instance.Parameter(
            displayName="Input Features",
            name="in_features",
            datatype="string",
            parameterType="Required",
            direction="Input")
         return param0

     # 2 - add a message - I put this on getParameterInfo, updateParameters, and execute and it never adds any msgs
    def test_method(arcpy_instance):
         def test_method(arcpy_instance):
             arcpy.AddMessage("Test method executed successfully.")
             arcpy.AddError("xyzxyzxyz.")


     # 3 - write to a file - this doesn't work - or breaks the tool
    def test_method():
         def test_method():
             def test_method():
        with open(r"some_dir\output.txt", "w") as f:
            f.write("test_method was called")&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;When called from execute, #3 builds but gives this when executed, even though #3 does not even have a "self" arg. These are all static methods. #1and #2 just do nothing and fail silently - the worst kind of failure.&lt;/P&gt;
&lt;LI-CODE lang="c"&gt;TestClass.test_method() missing 1 required positional argument: 'self'&lt;/LI-CODE&gt;
&lt;P&gt;All of them break&amp;nbsp;getParameterInfo if put there.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="Screenshot 2025-11-18 103045.png" style="width: 334px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/143999i5A76ED985CB9CC3A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2025-11-18 103045.png" alt="Screenshot 2025-11-18 103045.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I move this &lt;STRONG&gt;inside&lt;/STRONG&gt; the toolbox things now work.&lt;BR /&gt;Do you really need to put all the code inside one giant file?? B/c importing outside modules as shown is a total failure.&amp;nbsp;&lt;BR /&gt;What does it have to be so nasty to work with this....&lt;/P&gt;
&lt;LI-CODE lang="c"&gt;# this causes PermissionError: [Errno 13] Permission denied: - no matter what and I'm an admin.
def test_method_write():
    with open(r"some_path/file.txt", "w") as f:
        f.write("test_method was called!!!!!")

# this works as exepected
def test_method_param(mod):
    param0 = mod.Parameter(
        displayName="Input Features",
        name="in_features",
        datatype="string",
        parameterType="Required",
        direction="Input")
    return param0

# this works as exepected
def test_method_msg(mod):
   mod.AddMessage("Test message from test_method_msg")
   mod.AddWarning("Test warning from test_method_msg")
   mod.AddError("Test error from test_method_msg")

class Tool:
    def getParameterInfo(self):        
         return [test_method_param(arcpy)]


    def execute(self, parameters, messages):
        test_method_msg(arcpy)

&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Nov 2025 17:54:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-import-module-into-python-toolbox/m-p/1666783#M74918</guid>
      <dc:creator>chris_del101</dc:creator>
      <dc:date>2025-11-18T17:54:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to import module into python toolbox</title>
      <link>https://community.esri.com/t5/python-questions/how-to-import-module-into-python-toolbox/m-p/1666813#M74920</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/852729"&gt;@chris_del101&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I noticed that when you posted the error message, it mentions missing "self", this could be because the class methods on Python require a self variable to be in the function itself, so yours may be missing this self variable, for example this is a section of a toolbox I have:&lt;/P&gt;&lt;LI-CODE lang="c"&gt; def isLicensed(self):
        """Set whether tool is licensed to execute."""
        return True

    def updateParameters(self, parameters):
        """Modify the values and properties of parameters before internal
        validation is performed.  This method is called whenever a parameter
        has been changed."""
    

        return

    def updateMessages(self, parameters):
        """Modify the messages created by internal validation for each tool
        parameter.  This method is called after internal validation."""
        return&lt;/LI-CODE&gt;&lt;P&gt;I'm wondering if adding self will allow that?&lt;/P&gt;&lt;P&gt;Cody&lt;/P&gt;</description>
      <pubDate>Tue, 18 Nov 2025 18:46:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-import-module-into-python-toolbox/m-p/1666813#M74920</guid>
      <dc:creator>CodyPatterson</dc:creator>
      <dc:date>2025-11-18T18:46:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to import module into python toolbox</title>
      <link>https://community.esri.com/t5/python-questions/how-to-import-module-into-python-toolbox/m-p/1667209#M74933</link>
      <description>&lt;P&gt;Hi Cody,&lt;/P&gt;&lt;P&gt;I dont see any missing selfs. Here is the full code&lt;/P&gt;&lt;LI-CODE lang="c"&gt;test_class.py
class TestClass:
    def test_message_instance(self, arcpy_mod):
        arcpy_mod.AddMessage("Test message from test_method_msg instance")
    @staticmethod
    def test_message_static(arcpy_mod):
        arcpy_mod.AddMessage("Test message from test_method_msg static")
    @classmethod
    def test_message_class(cls, arcpy_mod):
        arcpy_mod.AddMessage("Test message from test_method_msg class")


my_toolbox.pyt
# tried with and without this - file in same dir - confirmed this is correct dir
import arcpy
sys.path.append(os.getcwd())
class Toolbox:
    def __init__(self):
        """Define the toolbox (the name of the toolbox is the name of the
        .pyt file)."""
        self.label = "Toolbox"
        self.alias = "toolbox"
       
        # List of tool classes associated with this toolbox
        self.tools = [Tool]


class Tool:
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "Tool"
        self.description = ""
        self.test_class = TestClass()

    def getParameterInfo(self):
       
        param0 = arcpy.Parameter(
            displayName="Input Features",
            name="in_features",
            datatype="string",
            direction="Input")

        return [param0]
    def isLicensed(self):
        """Set whether the tool is licensed to execute."""
        return True

    def updateParameters(self, parameters):
        # TestClass.test_method()
        """Modify the values and properties of parameters before internal
        validation is performed.  This method is called whenever a parameter
        has been changed."""
        return

    def updateMessages(self, parameters):
        """Modify the messages created by internal validation for each tool
        parameter. This m ethod is called after internal validation."""
        return

    def execute(self, parameters, messages):
        """The source code of the tool."""
        self.test_class.test_message_instance(arcpy)
        TestClass.test_message_static(arcpy)
        TestClass.test_message_class(arcpy)
    

        return

    def postExecute(self, parameters):
        """This method takes place after outputs are processed and
        added to the display."""
        return&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;AttributeError: 'TestClass' object has no attribute 'test_message_instance'&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Nov 2025 17:15:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-import-module-into-python-toolbox/m-p/1667209#M74933</guid>
      <dc:creator>chris_del101</dc:creator>
      <dc:date>2025-11-19T17:15:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to import module into python toolbox</title>
      <link>https://community.esri.com/t5/python-questions/how-to-import-module-into-python-toolbox/m-p/1667210#M74934</link>
      <description>&lt;P&gt;Hi Cody,&lt;/P&gt;&lt;P&gt;I dont see any missing selfs. Here is the full code&lt;/P&gt;&lt;LI-CODE lang="c"&gt;test_class.py
class TestClass:
    def test_message_instance(self, arcpy_mod):
        arcpy_mod.AddMessage("Test message from test_method_msg instance")
    @staticmethod
    def test_message_static(arcpy_mod):
        arcpy_mod.AddMessage("Test message from test_method_msg static")
    @classmethod
    def test_message_class(cls, arcpy_mod):
        arcpy_mod.AddMessage("Test message from test_method_msg class")


my_toolbox.pyt
# tried with and without this - file in same dir - confirmed this is correct dir
from test_class import TestClass
sys.path.append(os.getcwd())
class Toolbox:
    def __init__(self):
        """Define the toolbox (the name of the toolbox is the name of the
        .pyt file)."""
        self.label = "Toolbox"
        self.alias = "toolbox"
       
        # List of tool classes associated with this toolbox
        self.tools = [Tool]


class Tool:
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "Tool"
        self.description = ""
        self.test_class = TestClass()

    def getParameterInfo(self):
       
        param0 = arcpy.Parameter(
            displayName="Input Features",
            name="in_features",
            datatype="string",
            direction="Input")

        return [param0]
    def isLicensed(self):
        """Set whether the tool is licensed to execute."""
        return True

    def updateParameters(self, parameters):
        # TestClass.test_method()
        """Modify the values and properties of parameters before internal
        validation is performed.  This method is called whenever a parameter
        has been changed."""
        return

    def updateMessages(self, parameters):
        """Modify the messages created by internal validation for each tool
        parameter. This m ethod is called after internal validation."""
        return

    def execute(self, parameters, messages):
        """The source code of the tool."""
        self.test_class.test_message_instance(arcpy)
        TestClass.test_message_static(arcpy)
        TestClass.test_message_class(arcpy)
    

        return

    def postExecute(self, parameters):
        """This method takes place after outputs are processed and
        added to the display."""
        return&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;I still get&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;AttributeError: 'TestClass' object has no attribute 'test_message_instance'&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Nov 2025 17:04:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-import-module-into-python-toolbox/m-p/1667210#M74934</guid>
      <dc:creator>chris_del101</dc:creator>
      <dc:date>2025-11-19T17:04:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to import module into python toolbox</title>
      <link>https://community.esri.com/t5/python-questions/how-to-import-module-into-python-toolbox/m-p/1668259#M74943</link>
      <description>&lt;P&gt;After further investigation it might be that the modules are just not updating. I guess its this, although I'm not 100% sure:&amp;nbsp;&lt;A title="link" href="https://support.esri.com/en-us/knowledge-base/changes-made-to-embedded-script-in-a-python-script-tool-000011780" target="_self"&gt;link&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I currently have no way to do development since every change requires restarting pro - and there a hundreds of changes during development. Each restart takes 3-5 minutes.&lt;BR /&gt;Surely there must be a more orthodox way to do this?&lt;/P&gt;&lt;P&gt;They do say this, but I can't find the Export click they speak of:&lt;/P&gt;&lt;H2&gt;Workaround&lt;/H2&gt;&lt;P&gt;&lt;SPAN&gt;To make permanent changes to the source code, export the script by right-clicking it and clicking Export Script, make changes to the exported script, and import the script back if desired.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Nov 2025 17:37:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-import-module-into-python-toolbox/m-p/1668259#M74943</guid>
      <dc:creator>chris_del101</dc:creator>
      <dc:date>2025-11-24T17:37:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to import module into python toolbox</title>
      <link>https://community.esri.com/t5/python-questions/how-to-import-module-into-python-toolbox/m-p/1668800#M74947</link>
      <description>&lt;P&gt;I've got a simple framework that solves this here: &lt;A href="https://github.com/hwelch-fle/pytframe2" target="_blank" rel="noopener"&gt;https://github.com/hwelch-fle/pytframe2&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This method also makes sure that submodules are refreshed when the toolbox is refreshed, since by default the imported modules aren't reloaded until the interpreter is restarted (reboot ArcPro). This definitely makes it easier to develop a tool since you just refresh the toolbox and the new code is loaded in instantly as long as it's part of that reload chain.&lt;/P&gt;&lt;P&gt;I'm trying to add a lot of that functionality into a more holistic library under &lt;A href="https://github.com/hwelch-fle/arcpie" target="_blank" rel="noopener"&gt;https://github.com/hwelch-fle/arcpie&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another note, all class methods in Python require a self argument since calling a method on an object passes self as arg0 even with no arguments.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Nov 2025 15:44:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-import-module-into-python-toolbox/m-p/1668800#M74947</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2025-11-26T15:44:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to import module into python toolbox</title>
      <link>https://community.esri.com/t5/python-questions/how-to-import-module-into-python-toolbox/m-p/1669355#M74952</link>
      <description>&lt;P&gt;Try using importlib.reload()?&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.geeksforgeeks.org/python/reloading-modules-python/" target="_blank"&gt;Reloading modules in Python - GeeksforGeeks&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Dec 2025 15:41:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-import-module-into-python-toolbox/m-p/1669355#M74952</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2025-12-01T15:41:14Z</dc:date>
    </item>
  </channel>
</rss>

