title: Load all modules (files) in directory without prefixes
body: <p>I am using python 2.7. I have a folder with a number of .py files in it that define functions, load objects, etc. that I would like to use in my main script.  I want to accomplish the following two objectives:</p>
  
  <ol>
  <li>Load all objects from all .py files in this directory, without knowing the file names in advance.</li>
  <li>Access these objects in my main script without prefixing, e.g. without needing to use <code>filename.function_name()</code></li>
  </ol>
  
  <p>I understand that this does not conform to accepted best practices for python modules.  Nevertheless:</p>
  
  <ul>
  <li><p>I am writing code purely for my own use.  It will never be shared with or used by others.</p></li>
  <li><p>In the course of my development work, I frequently change the names of files, move object definitions from one file to another, etc.  Thus, it is cumbersome to need to go to my main script and change the names of the function name prefixes each time I do this.</p></li>
  <li><p>I am an adult.  I understand the concept of risks from name conflicts.  I employ my own naming conventions with functions and objects I create to ensure they won't conflict with other names.</p></li>
  </ul>
  
  <p>My first shot at this was to just loop through the files in the directory using <code>os.listdir()</code> and then call <code>execfile()</code> on those.  When this did not work, I reviewed the responses here: <a href="https://stackoverflow.com/questions/1057431/loading-all-modules-in-a-folder-in-python">Loading all modules in a folder in Python</a>  .  I found many helpful things, but none get me quite where I want.  Specifically, if include in my <code>__init__.py</code> file the response <a href="https://stackoverflow.com/a/1057534/3541976">here</a>:</p>
  
  <pre><code>from os.path import dirname, basename, isfile
  import glob
  modules = glob.glob(dirname(__file__)+"/*.py")
  __all__ = [ basename(f)[:-3] for f in modules if isfile(f)]
  </code></pre>
  
  <p>and then use in my main script:</p>
  
  <pre><code>os.chdir("/path/to/dir/") # folder that contains `Module_Dir`
  from Module_Dir import *
  </code></pre>
  
  <p>then I can gain access to all of the objects defined in the files in my directory without needing to know the names of those files ahead of time (thus satisfying #1 from my objectives).  But, this still requires me to call upon those functions and objects using <code>filename.function_name()</code>, etc.  Likewise, if I include in my <code>__init__.py</code> file explicitly:</p>
  
  <pre><code>from filename1 import *
  from filename2 import *
  etc.
  </code></pre>
  
  <p>Then I can use in my main script the same <code>from Module_Dir import *</code> as above.  Now, I get access to my objects without the prefixes, but it requires me to specify explicitly the names of the files in <code>__init__.py</code>.</p>
  
  <p>Is there a solution that can combine these two, thus accomplishing both of my objectives?  I also tried (as suggested <a href="https://stackoverflow.com/a/1057765/3541976">here</a>, for instance, including the following in <code>__init__.py</code>:</p>
  
  <pre><code>import os
  for module in os.listdir(os.path.dirname(__file__)):
      if module == '__init__.py' or module[-3:] != '.py':
          continue
      __import__(module[:-3], locals(), globals())
  del module
  </code></pre>
  
  <p>But again, this still required the name prefixing.  I tried to see if there were optional arguments or modifications to how I use <code>__import__</code> here, or applications using python 2.7's importlib, but did not make progress on either front.</p>