package introspection...

Brett C. drifty at bigfoot.com
Tue Feb 25 00:30:29 EST 2003


Skip Montanaro <skip at pobox.com> wrote in message:
>     def pkgdir(mod):
>         contents = dir(mod)
>         if hasattr(mod, "__file__"):
>             contents += ["[%s]"%os.path.splitext(p)[0]
>                           for p in os.listdir(os.path.dirname(mod.__file__))
>                             if (p.endswith(".py") or p.endswith(".so")) and
>                                 os.path.splitext(p)[0] not in contents and
>                                 p != "__init__.py"]
>         contents.sort()
>         return contents
> 
> if someone doesn't have a better suggestion.

Cool solution.  The only issue I see with it is if for some odd reason
someone only includes .pyc or .pyd files.  There is also the issue of
zip files now that we have zip packages (and this of course leads to
more issues thanks to import hooks  =).

Regardless of any of that, though, this is still nice and makes me
wish this was part of the core somehow.

-Brett




More information about the Python-list mailing list