MCPcopy Create free account
hub / github.com/ipython/ipython / import_item

Function import_item

IPython/utils/importstring.py:10–39  ·  view source on GitHub ↗

Import and return ``bar`` given the string ``foo.bar``. Calling ``bar = import_item("foo.bar")`` is the functional equivalent of executing the code ``from foo import bar``. Parameters ---------- name : string The fully qualified name of the module/package being imported.

(name)

Source from the content-addressed store, hash-verified

8
9
10def import_item(name):
11 """Import and return ``bar`` given the string ``foo.bar``.
12
13 Calling ``bar = import_item("foo.bar")`` is the functional equivalent of
14 executing the code ``from foo import bar``.
15
16 Parameters
17 ----------
18 name : string
19 The fully qualified name of the module/package being imported.
20
21 Returns
22 -------
23 mod : module object
24 The module that was imported.
25 """
26
27 parts = name.rsplit('.', 1)
28 if len(parts) == 2:
29 # called with 'foo.bar....'
30 package, obj = parts
31 module = __import__(package, fromlist=[obj])
32 try:
33 pak = getattr(module, obj)
34 except AttributeError:
35 raise ImportError('No module named %s' % obj)
36 return pak
37 else:
38 # called with un-dotted string
39 return __import__(parts[0])

Callers 11

get_ipython_module_pathFunction · 0.90
test_import_plainFunction · 0.90
test_import_nestedFunction · 0.90
_import_appMethod · 0.90
_default_loop_runnerMethod · 0.90
_import_runnerMethod · 0.90
autoawaitMethod · 0.90
test_forFunction · 0.90
find_moduleMethod · 0.85
load_moduleMethod · 0.85
__getattr__Method · 0.85

Calls

no outgoing calls

Tested by 3

test_import_plainFunction · 0.72
test_import_nestedFunction · 0.72
test_forFunction · 0.72