Python Glossary Русский

all Python 3until 3.14Removed from the standard libraryfunction

pkgutil.get_loader()

removed

Returned the loader for a module given its name or module object. Removed in Python 3.14 — use importlib.util.find_spec().

Syntax

pkgutil.get_loader('json')  # до 3.14

get_loader took a name or an already imported module and returned its loader — that is how people read a module's source through loader.get_source(). It was removed together with find_loader, since the loader is now part of the module spec. To migrate: for a name use importlib.util.find_spec(name).loader; for an imported module use module.__spec__.loader; to read the source, call get_source(name) on that loader as before.

Examples

# Python 3.14+
import pkgutil
try:
    pkgutil.get_loader
except AttributeError as e:
    print(type(e).__name__)  # → AttributeError
# Python 3.14+
import importlib.util
import json
loader = json.__spec__.loader
print(loader is importlib.util.find_spec('json').loader)  # → True
print('JSONDecoder' in loader.get_source('json'))  # → True
import json
import pkgutil
loader = pkgutil.get_loader(json)
print(type(loader).__name__)  # → SourceFileLoader
print('JSONDecoder' in loader.get_source('json'))  # → True

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy