<?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 Importing Python Modules in the Python addin in Python AddIns Questions</title>
    <link>https://community.esri.com/t5/python-addins-questions/importing-python-modules-in-the-python-addin/m-p/774858#M32</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've been working in the python addin environment for the past few months.&amp;nbsp; One of the projects I've undertaken is a series of QA QC routines that run independent of each other.&amp;nbsp; My first stab was to run each of the routines under the onClick function of one button on a toolbar.&amp;nbsp; In doing so, I'm able to import various python modules needed once, right up at the top of the script where arcpy and pythonaddins are, before any button classes are defined.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, after working on another project for a few weeks, and returning to the QA QC project, I found the code to be difficult to read and/or maintain so I decided to define each of the processes as their own function, and simply call them from the button&amp;nbsp; onClick function.&amp;nbsp; Many of these routines / functions use modules like string, and from string, punctuation and ascii_letters.&amp;nbsp; With the the more modular approach I have found that each of 'extra' python modules need to be imported with each function.&amp;nbsp; That is, I import string a half a dozen times in each of my 6 functions that use it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Seems like&amp;nbsp;I should be able to "share" imported python modules across my defined functions, but I must be missing something along the way.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 20 Feb 2018 16:51:25 GMT</pubDate>
    <dc:creator>JoeBorgione</dc:creator>
    <dc:date>2018-02-20T16:51:25Z</dc:date>
    <item>
      <title>Importing Python Modules in the Python addin</title>
      <link>https://community.esri.com/t5/python-addins-questions/importing-python-modules-in-the-python-addin/m-p/774858#M32</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've been working in the python addin environment for the past few months.&amp;nbsp; One of the projects I've undertaken is a series of QA QC routines that run independent of each other.&amp;nbsp; My first stab was to run each of the routines under the onClick function of one button on a toolbar.&amp;nbsp; In doing so, I'm able to import various python modules needed once, right up at the top of the script where arcpy and pythonaddins are, before any button classes are defined.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, after working on another project for a few weeks, and returning to the QA QC project, I found the code to be difficult to read and/or maintain so I decided to define each of the processes as their own function, and simply call them from the button&amp;nbsp; onClick function.&amp;nbsp; Many of these routines / functions use modules like string, and from string, punctuation and ascii_letters.&amp;nbsp; With the the more modular approach I have found that each of 'extra' python modules need to be imported with each function.&amp;nbsp; That is, I import string a half a dozen times in each of my 6 functions that use it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Seems like&amp;nbsp;I should be able to "share" imported python modules across my defined functions, but I must be missing something along the way.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Feb 2018 16:51:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-addins-questions/importing-python-modules-in-the-python-addin/m-p/774858#M32</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2018-02-20T16:51:25Z</dc:date>
    </item>
    <item>
      <title>Re: Importing Python Modules in the Python addin</title>
      <link>https://community.esri.com/t5/python-addins-questions/importing-python-modules-in-the-python-addin/m-p/774859#M33</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Joe...Once a module (ie string) is imported, it claims namespace and even if reimported it doesn't do anything since it is already loaded.&amp;nbsp; It is good practice to include the imports inside each of your scripts (aka, modules) since you don't know which will be used first I suspect.&amp;nbsp; So unless you want to import everything that you&lt;EM&gt; 'might'&lt;/EM&gt; use during a session, just place the import statements where you need them.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Feb 2018 19:06:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-addins-questions/importing-python-modules-in-the-python-addin/m-p/774859#M33</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2018-02-20T19:06:58Z</dc:date>
    </item>
    <item>
      <title>Re: Importing Python Modules in the Python addin</title>
      <link>https://community.esri.com/t5/python-addins-questions/importing-python-modules-in-the-python-addin/m-p/774860#M34</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;PS... the order of imports should be&lt;/P&gt;&lt;P&gt;system modules&lt;/P&gt;&lt;P&gt;other modules&lt;/P&gt;&lt;P&gt;your modules&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ie&lt;/P&gt;&lt;P&gt;import sys &amp;nbsp; &amp;nbsp;&amp;nbsp; # this&lt;/P&gt;&lt;P&gt;import os &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; # and this are often imported by other modules&lt;/P&gt;&lt;P&gt;import numpy &amp;nbsp; # this one next since it is 'pure' except for system module imports (sys and sometimes os)&lt;/P&gt;&lt;P&gt;import scipy &amp;nbsp; &amp;nbsp; # imports numpy all over the place&lt;/P&gt;&lt;P&gt;import pandas&amp;nbsp; # imports numpy etc&lt;/P&gt;&lt;P&gt;import Joes_Amazing_Address_Tools&amp;nbsp; # this might be a toolset that you want to import and use infrequently... you can import sys,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; os etc there as well, they just won't get reimported&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Feb 2018 19:15:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-addins-questions/importing-python-modules-in-the-python-addin/m-p/774860#M34</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2018-02-20T19:15:50Z</dc:date>
    </item>
    <item>
      <title>Re: Importing Python Modules in the Python addin</title>
      <link>https://community.esri.com/t5/python-addins-questions/importing-python-modules-in-the-python-addin/m-p/774861#M35</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Dan-&amp;nbsp; thought I may be making another rookie mistake....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Feb 2018 19:26:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-addins-questions/importing-python-modules-in-the-python-addin/m-p/774861#M35</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2018-02-20T19:26:55Z</dc:date>
    </item>
  </channel>
</rss>

