On this page
pkgutil.walk_packages
Prev: pkgutil.read_code | Up: pkgutil
Rel: pkgutil.extend_path, pkgutil.get_data, pkgutil.get_importer, pkgutil.iter_importers
Ref: docs.python.org — pkgutil.walk_packages
Tags: #public #python3 #stdlib #pkgutil
Import
import pkgutil
from pkgutil import walk_packages
Signature & Overview
pkgutil.walk_packages(path=None, prefix='', onerror=None)
Yields ModuleInfo for all modules recursively on path, or, if path is None, all accessible modules.
Usage
import json
import pkgutil
found = [m.name for m in pkgutil.walk_packages(json.__path__, prefix="json.")]
assert "json.decoder" in found
Gotchas
- IMPORTS every subpackage it descends into: Pass
onerror=lambda name: Noneif broken optional subpackages shouldn't abort the walk.
REPL Inspect
from pkgutil import walk_packages
help(walk_packages)
Linked from
Related notes
- tuts/python3/stdlib_module/pkgutil/read_code Linked here; links to this page; shared tags: #pkgutil, #stdlib
- tuts/python3/stdlib_module/pkgutil Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/pkgutil/extend_path Linked here; shared tags: #pkgutil, #stdlib
- tuts/python3/stdlib_module/pkgutil/get_data Linked here; shared tags: #pkgutil, #stdlib
- tuts/python3/stdlib_module/pkgutil/get_importer Linked here; shared tags: #pkgutil, #stdlib
- tuts/python3/stdlib_module/pkgutil/iter_importers Linked here; shared tags: #pkgutil, #stdlib
- tuts/python3/stdlib_module/pkgutil/iter_modules shared tags: #pkgutil, #stdlib
- tuts/python3/stdlib_module/pkgutil/ModuleInfo shared tags: #pkgutil, #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib