title: Module path dependencies
body: <p>Lets assume the following structure of directories for a project</p>
  
  <pre><code>&lt;root&gt;
    __init__.py
    helloworld.py
  &lt;moduleOne&gt;
    f.txt
    __init__.py
    printfile.py
  </code></pre>
  
  <p>where root and moduleOne are directories</p>
  
  <p>Content of helloworld.py:</p>
  
  <pre><code>#!/usr/bin/python
  import helloworld.printfile
  printf()
  </code></pre>
  
  <p>Content of moduleOne/printfile</p>
  
  <pre><code>#!/usr/bin/python
  f = open('f.txt')
  
  def printf():
      print 'print file'
      print f
  
  if __name__ == '__main__':
     printf()
  </code></pre>
  
  <p>My issue:</p>
  
  <p>From moduleOne/ the execution of printfile is ok, but from root/, if i run helloworld.py the following error happens:</p>
  
  <pre><code>import moduleOne.printfile
  File "/root/moduleOne/printfile.py", line 5, in &lt;module&gt;
   f = open('f.txt')
  IOError: [Errno 2] No such file or directory: 'f.txt'
  </code></pre>
  
  <p>How to solve this in python?</p>
  
  <p>[Edited]</p>
  
  <p>I solved (more or less) this issue with a "workaround", but stil have a problem:</p>
  
  <p>My solution:</p>
  
  <p>In moduleOne/printfile</p>
  
  <pre><code>import sys
  fname = 'moduloOne/f.txt'
  
  def printf():
  
      f = open(fname)
      print 'print file'  
      print f
  
  if __name__ == '__main__':
  
      fname = 'f.txt'
      printf()    
  </code></pre>
  
  <p>But....</p>
  
  <p>lets say i have a new directory, from the root, called etc, then the new structure is:</p>
  
  <pre><code>&lt;root&gt;
    __init__.py
    helloworld.py
  &lt;moduleOne&gt;
    f.txt
    __init__.py
    printfile.py
  &lt;etc&gt;
    f2.txt
  </code></pre>
  
  <p>And now i need to acess etc/f2.txt from moduleOne/printfile. how?</p>