<?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 Modules for Dummy in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/modules-for-dummy/m-p/299813#M23188</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have been diving through Python this year and have gotten stuck at modules.&amp;nbsp; I have four scripts that perform some awesome fixes for MXDs when there is a database change.&amp;nbsp; However, I have to put the same functions and variables at the top of each one of the scripts.&amp;nbsp; I was thinking of turning this into a module or package?&amp;nbsp; I cannot seem to figure these module/packages out.&amp;nbsp; My question is for Python 2.6.5/ArcGIS 10...&amp;nbsp; What would need to be in __init__.py?&amp;nbsp; How would I set up the global variables/functions for all the scripts to use?&amp;nbsp; How do I register all the scripts to be able to recognize what went on in the others?&amp;nbsp; I have tried the helps out there but am further lost.&amp;nbsp; Maybe someone can help me and then I can fix and post my product?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 07 Jun 2013 17:18:56 GMT</pubDate>
    <dc:creator>MaryM</dc:creator>
    <dc:date>2013-06-07T17:18:56Z</dc:date>
    <item>
      <title>Modules for Dummy</title>
      <link>https://community.esri.com/t5/python-questions/modules-for-dummy/m-p/299813#M23188</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have been diving through Python this year and have gotten stuck at modules.&amp;nbsp; I have four scripts that perform some awesome fixes for MXDs when there is a database change.&amp;nbsp; However, I have to put the same functions and variables at the top of each one of the scripts.&amp;nbsp; I was thinking of turning this into a module or package?&amp;nbsp; I cannot seem to figure these module/packages out.&amp;nbsp; My question is for Python 2.6.5/ArcGIS 10...&amp;nbsp; What would need to be in __init__.py?&amp;nbsp; How would I set up the global variables/functions for all the scripts to use?&amp;nbsp; How do I register all the scripts to be able to recognize what went on in the others?&amp;nbsp; I have tried the helps out there but am further lost.&amp;nbsp; Maybe someone can help me and then I can fix and post my product?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Jun 2013 17:18:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/modules-for-dummy/m-p/299813#M23188</guid>
      <dc:creator>MaryM</dc:creator>
      <dc:date>2013-06-07T17:18:56Z</dc:date>
    </item>
    <item>
      <title>Re: Modules for Dummy</title>
      <link>https://community.esri.com/t5/python-questions/modules-for-dummy/m-p/299814#M23189</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Chose or make one script for the main process.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import all the other scripts (modules) into it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You may want to adjust the python path to make sure your modules are found&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;This can be done temporarily (for the session) by using&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sys.path.append(customPath)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;where customPath is the path to your modules.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;set this before the custom module imports&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;set up the modules with function defs.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I like pass all the objects, modules and variables used in the function into it as arguments.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for example, in a hypothetical customModule_2:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def processTheData(arcpy, sys,
&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; customModule_3,
&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; customModuleToolConfig,
&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; customModuleToolHelper,
&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; variable1, variable2, listA):&lt;/PRE&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then invoke it like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;return_2 = customModule_2.processTheData(arcpy, sys,
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; customModule_3,
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; customModuleToolConfig,
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; customModuleToolHelper,
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "Whoppie!", 2013, listOfStuff)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The return can be whatever you want back:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;even if it is just a boolean for sucsessful completion.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;below all the def / functions in the supporting modules,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;one can add something like &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; safety
if __name__ == "__main__":
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "This script does not run alone."&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;so the module script won't try to the start the overall process in the middle.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As well, once the whole process is running correctly, &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;a .pyc file will have been generated for each imported module.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;At that point you can remove those .py files from the accessable directory.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It is not perfect security, but it means no one can casually damage the script&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;by "just lookin' at it" in a text editor.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Leave the main script as a py, and maybe a configuration module, too, for easy modification.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:22:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/modules-for-dummy/m-p/299814#M23189</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2021-12-11T14:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: Modules for Dummy</title>
      <link>https://community.esri.com/t5/python-questions/modules-for-dummy/m-p/299815#M23190</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Okay, setting up the modules to run with all the objects being passed to them may help my problem.&amp;nbsp; Does anything need to be in __init__.py?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Jun 2013 18:27:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/modules-for-dummy/m-p/299815#M23190</guid>
      <dc:creator>MaryM</dc:creator>
      <dc:date>2013-06-07T18:27:02Z</dc:date>
    </item>
    <item>
      <title>Re: Modules for Dummy</title>
      <link>https://community.esri.com/t5/python-questions/modules-for-dummy/m-p/299816#M23191</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Not likely, but it depends on what you are trying to do.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Jun 2013 18:37:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/modules-for-dummy/m-p/299816#M23191</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2013-06-07T18:37:30Z</dc:date>
    </item>
  </channel>
</rss>

