title: Imported code cannot open files in its directory
body: <p>I have the following file structure:</p>
  
  <pre><code>test/
      test1.py
  test2.py
  text.txt
  </code></pre>
  
  <p>Here are the contents of the files</p>
  
  <p><strong>test1.py:</strong></p>
  
  <pre><code>import sys
  sys.path.append('../')
  import test2
  
  test2.read()
  </code></pre>
  
  <p><strong>test2.py:</strong></p>
  
  <pre><code>def read():
      with open('text.txt', 'rb') as f:
          print f.read()
  
  if __name__ == "__main__":
      read()
  </code></pre>
  
  <p><code>text.txt</code> contains a line of text. When I run <code>test1.py</code>, I get a "File not found" error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "test1.py", line 5, in &lt;module&gt;
      test2.read()
    File "../test2.py", line 2, in read
      with open('text.txt', 'rb') as f:
  IOError: [Errno 2] No such file or directory: 'text.txt'
  </code></pre>
  
  <p>I kind of understand why this error is coming up. But how do I deal with these kind of errors. I would like the code in <code>test2.py</code> to be like library code which I can use anywhere.</p>