Presume I have a package &#39;a&#39; like this:<br><ul style="font-family: courier new,monospace;"><li>/pystuff  (added to sys.path)<br></li><ul><li>/a  (start of my package)<br></li><ul><li>__init__.py<br></li><li>/b  </li>
<ul><li>__init__.py</li><li>module.py</li></ul></ul></ul></ul>to import module.py:<br><span style="font-family: courier new,monospace;">import </span><b style="font-family: courier new,monospace;">a.b.module</b><br><br>What I&#39;m trying to find is a way to query exactly what I typed above (in bold):  Inside of module.py, can it query it&#39;s path back to the package root?  Printing __file__ inside of module.py is close:<br>
<span style="font-family: courier new,monospace;">c:/pystuff/a/b/module.py</span><br><br>But I just want &#39;<b style="font-family: courier new,monospace;">a.b.module&#39;</b><br>I can search sys.path for paths, remove them from __file__, switch slashes to dots, strip extensions, etc.  But I&#39;ve learned that there&#39;s usually something easier in Python that I&#39;m just missing.  I thought maybe the inspect module, but I didn&#39;t have any luck there, nor did my Google queries.<br>
<br>thanks<br>