python - List modules in namespace package -


i'm trying python list modules in namespace package.

i have following file structure:

cwd |--a |  `--ns |     |--__init__.py |     `--amod.py |--b |  `--ns |     |--__init__.py |     `--bmod.py `--c    `--ns       |--__init__.py       `--cmod.py 

each __init__.py defines it's package namespace package having following line:

__import__('pkg_resources').declare_namespace(__name__) 

the amod module contains class a, bmod contains class b , cmod contains c class.

when having clean environment following happens:

>>> import inspect, sys, glob >>> sys.path += glob.glob('*') >>> import ns >>> inspect.getmembers(ns, inspect.ismodule) [] 

as can see, modules not listed.

now when import modules manually , call inspect again:

>>> inspect.getmembers(ns, inspect.ismodule) [('amod', <module 'ns.amod' 'a/ns/amod.pyc'>), ('bmod', <module 'ns.bmod' 'b/ns/bmod.pyc'>), ('cmod', <module 'ns.cmod' 'c/ns/cmod.pyc'>)] 

now i'd inspect call work without importing modules manually, how can achieve this?


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -