How to get the name/list of all submodules of an already imported Python module? (Not the external imported module/packages, just that one in the same folder as module sub-folder).
I am using
import inspect
print([o[0] for o in inspect.getmembers(module_imported) if inspect.ismodule(o[1])])
but this print also the system modules imported and files in the main module folder.
We can list down all the functions present in a Python module by simply using the dir() method in the Python shell or in the command prompt shell.
In my limited experience, modules with submodules are simply folders with a __init__.py file, while modules with functions/classes are actual python files.
We've then used the dir () function to display the attributes provided by the module. Here is a brief description of the attributes: Bye, Welcome – the functions provided by the module. __builtins__ – a listing of all the built-in attributes that are accessible from the module.
The Pip, Pipenv, Anaconda Navigator, and Conda Package Managers can all be used to list installed Python packages. You can also use the ActiveState Platform's command line interface (CLI), the State Tool to list all installed packages using a simple “state packages” command.
Use pkgutil
, though it doesn't always work with pyinstaller.
pkgutil.iter_modules(imported_module.__path__))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With