PyDocs

Nav

Python Runtime Services

__import__

builtins

function
  • __import__(name, globals=None, locals=None, fromlist=(), level=0)
Import a module.

Because this function is meant for use by the Python
interpreter and not for general use, it is better to use
importlib.import_module() to programmatically import a module.

The globals argument is only used to determine the context;
they are not modified.  The locals argument is unused.  The fromlist
should be a list of names to emulate ``from name import ...``, or an
empty list to emulate ``import name``.
When importing a module from a package, note that __import__('A.B', ...)
returns package A when fromlist is empty, but its submodule B when
fromlist is not empty.  The level argument is used to determine whether
to perform absolute or relative imports: 0 is absolute, while a positive
number is the number of parent directories to search relative to the
current module.
Changed in 3.3, 3.9
  • 3.3: Negative values for level are no longer supported (which also changes the default value to 0).
  • 3.9: When the command line options -E or -I are being used, the environment variable PYTHONCASEOK is now ignored.
0 Examples
No examples for builtins/__import__.
See Also
No see-alsos for builtins/__import__
0 Notes
No notes for __import__