title: python local modules
body: <p>I have several project directories and want to have libraries/modules that are specific to them. For instance, I might have a directory structure like such:</p>
  
  <pre><code>myproject/
    mymodules/
      __init__.py
      myfunctions.py
    myreports/
      mycode.py
  </code></pre>
  
  <p>Assuming there is a function called <code>add</code> in <code>myfunctions.py</code>, I can call it from <code>mycode.py</code> with the most naive routine:</p>
  
  <pre><code>execfile('../mymodules/myfunctions.py')
  add(1,2)
  </code></pre>
  
  <p>But to be more sophisticated about it, I can also do</p>
  
  <pre><code>import sys
  sys.path.append('../mymodules')
  import myfunctions
  
  myfunctions.add(1,2)
  </code></pre>
  
  <p>Is this the most idiomatic way to do this? There is also some mention about modifying the <code>PYTHONPATH</code> (<code>os.environ['PYTHONPATH']</code>?), but is this or other things I should look into?</p>
  
  <p>Also, I have seen <code>import</code> statements contained within class statements, and in other instances, defined at the top of a Python file which contains the class definition. Is there a right/preferred way to do this?</p>