reflection - Getting all functions of python package -
i have multimodule python package has 1 file class myclass
, few files functions (one file can contain more 1 function).
i tried functions in package.
firstly, using following:
modules = [] importer, module, ispkg in pkgutil.iter_modules(package.__path__): modules.extend(module)
but got module names, not module objects.
when tried functions of these modules using inspect.getmembers(module, inspect.isfunction)
, of course, got empty collection.
so, how can got module objects package further getting functions?
does easier way functions multifile package exists?
p.s. need function
objects , not names.
edit.
dir(package)
gives me built-in variables:['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__']
inspect.getmembers(package, inspect.infunction)
gives empty list same code eachmodule
described above.dir(module)
gives me name list of methods availablestr
objects (because,iter_modules()
gives names of modules).ast... sure, there isn't simpler solutions?
try this:
for importer, module, ispkg in pkgutil.iter_modules(package.__path__): print dir(__import__(module))
Comments
Post a Comment