MCPcopy Index your code
hub / github.com/python/cpython / import_module

Function import_module

Lib/importlib/__init__.py:71–88  ·  view source on GitHub ↗

Import a module. The 'package' argument is required when performing a relative import. It specifies the package to use as the anchor point from which to resolve the relative import to an absolute import.

(name, package=None)

Source from the content-addressed store, hash-verified

69
70
71def import_module(name, package=None):
72 """Import a module.
73
74 The 'package' argument is required when performing a relative import. It
75 specifies the package to use as the anchor point from which to resolve the
76 relative import to an absolute import.
77
78 """
79 level = 0
80 if name.startswith('.'):
81 if not package:
82 raise TypeError("the 'package' argument is required to perform a "
83 f"relative import for {name!r}")
84 for character in name:
85 if character != '.':
86 break
87 level += 1
88 return _bootstrap._gcd_import(name[level:], package, level)
89
90
91_RELOADING = {}

Callers 11

conf.pyFile · 0.90
test_resource_pathMethod · 0.90
runFunction · 0.90
loadMethod · 0.90

Calls 1

startswithMethod · 0.45

Tested by 9

test_resource_pathMethod · 0.72
runFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…