title: How to properly set the path to input/output file?
body: <p>I am working on part of a Python project and the structure is like this:
  <code>project/some_folder/another_folder/my_work</code>.</p>
  
  <p>In this folder, the file containing the code is <code>run.py</code>.
  In the same folder, I also have an <code>input_file</code> from which I read some data, process it, and write the result to <code>output_file</code>.
  So in <code>run.py</code> I have something like:</p>
  
  <pre><code>with open("input_file") as f:
      do_something()
  </code></pre>
  
  <p>and</p>
  
  <pre><code>with open("output_file") as f:
      store_the_result()
  </code></pre>
  
  <p>This works fine when I execute the code in <code>project/some_folder/another_folder/my_work</code>.
  However, when I go to <code>project</code> and run the code using <code>python -m some_folder.another_folder.my_work.run</code>, I will have trouble accessing the input file.
  I tried to solve this problem by using the aboslute path to the files, but this will only work on my machine. If someone copies my code to his/her machine, he/she still needs to modify the hardcoded absolute path.</p>
  
  <p>How to set the path to the files such that I can start the program either in the folder containing the input and output file, or run it as a module, and others will not need to modify the path to the file when running code on their machines?</p>