Tell python to access resources above the path of the script
<p>If you run a script from /tmp/myfolder/myscript/, and want to access a resource in myfolder, how do you do that in python?</p>

<p>I did get the file path with <code>__file__</code>, (I was told to not use it because it may not always be populated) but I can't do like in bash, where I "cd .."  to get to the previous directory, because Python does not understand that.</p>

<p>I would like to run the python script and no matter where the folder is, it will always go up one level and get the resource that I need.</p>

<p>I am unclear about exactly what you are talking about, but I infer that you are talking about intra-package references. You can read more about it <a href="https://docs.python.org/3/tutorial/modules.html" rel="nofollow">here</a>, but the general concept is you use <code>from .. import module</code> when trying to import a module from another package. </p>

<p>The <code>..</code> in the statement tells the compiler to go up one level and look for a module named <code>module</code>. You can also use <code>for . import module</code>, which will import the 
module <code>name</code> from the current directory and <code>from ../folder import module</code></p>

python