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.

  1. dir(package) gives me built-in variables:

    ['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__']

  2. inspect.getmembers(package, inspect.infunction) gives empty list same code each module described above.

  3. dir(module) gives me name list of methods available str objects (because, iter_modules() gives names of modules).

  4. ast... sure, there isn't simpler solutions?

try this:

for importer, module, ispkg in pkgutil.iter_modules(package.__path__):    print dir(__import__(module)) 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -