Presume I have a package 'a' 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'm trying to find is a way to query exactly what I typed above (in bold): Inside of module.py, can it query it'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 '<b style="font-family: courier new,monospace;">a.b.module'</b><br>I can search sys.path for paths, remove them from __file__, switch slashes to dots, strip extensions, etc. But I've learned that there's usually something easier in Python that I'm just missing. I thought maybe the inspect module, but I didn't have any luck there, nor did my Google queries.<br>
<br>thanks<br>