I have a multimodule Python package which has one file with class MyClass
and few files with functions (one file can contain more than 1 function).
I tried to get all functions in this package.
Firstly, using the following:
modules = []
for importer, module, ispkg in pkgutil.iter_modules(package.__path__):
modules.extend(module)
but I got only module names, not module objects.
When I tried to get functions of these modules using inspect.getmembers(module, inspect.isfunction)
, I of course, got an empty collection.
So, how can I got all module objects from the package for further getting functions?
Does an easier way to get all functions from the multifile package exists?
P.S. I need exactly function
objects and not only their names.
Edit.
-
dir(package)
gives me only built-in variables:['builtins', 'doc', 'file', 'name', 'package', 'path']
-
inspect.getmembers(package, inspect.infunction)
gives an empty list as well as the same code for eachmodule
as I described above. -
dir(module)
gives me the name list of all methods available forstr
objects (because,iter_modules()
gives only names of modules). -
AST... Are you sure, that there isn't simpler solutions?
Aucun commentaire:
Enregistrer un commentaire