Python : How to access file from different directory <p>I have the following project structure</p> <pre><code>SampleProject com python example source utils ConfigManager.py conf constants.cfg </code></pre> <p>How to access constants.cfg from ConfigManager.py. </p> <p>I have a limitation</p> <ol> <li>I can not give full path(absolute path) of constants.cfg because if I run in different PC it should work with out any modification</li> <li><p>Also if I represent something like below, I can access the file. But I don't want to give back slash every time</p> <pre><code>filename = ..\\..\\..\\..\\..\\..\\constants.cfg` </code></pre></li> </ol> <p>Currently I am doing something like this. But this works only when constants.cfg and ConfigManager.py are in same directory</p> <pre><code>currentDir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) file = open(os.path.join(currentDir,'constants.cfg')) </code></pre>