[Tutor] Querying a module's package path?
Eric Pavey
warpcat at gmail.com
Wed Nov 11 02:12:02 CET 2009
Presume I have a package 'a' like this:
- /pystuff (added to sys.path)
- /a (start of my package)
- __init__.py
- /b
- __init__.py
- module.py
to import module.py:
import *a.b.module*
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:
c:/pystuff/a/b/module.py
But I just want '*a.b.module'*
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.
thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091110/480a9196/attachment.htm>
More information about the Tutor
mailing list