Way to access resource files in python
<p>What is the proper way to access resources in python programs. </p>

<p>Basically in many of my python modules I end up writing code like that: </p>

<pre><code>  DIRNAME = os.path.split(__file__)[0]

  (...) 

  template_file = os.path.join(DIRNAME, "template.foo")
</code></pre>

<p>Which is OK but: </p>

<ul>
<li>It will break if I will start to use python zip packages</li>
<li>It is boilerplate code</li>
</ul>

<p>In Java I had a function that did exactly the same --- but worked both when code was lying in bunch of folders and when it was packaged in <code>.jar</code> file. </p>

<p>Is there such function in Python, or is there any other pattern that I might use. </p>
