__Import __ () function in Python

__Import __ () is an advanced function called by the import statement in Python

__import __ () is an advanced function called by the import statement in Python.

The __import __ () syntax in Python

 __import__(name, globals=None, locals=None, fromlist=(), level=0) 

The parameter of __import function __ ():

  1. name : the name of the module to import.
  2. globals and locals : used to determine name interpretation.
  3. fromlist : names of objects or sub-models should be entered from the provided module by name .
  4. level : specifies whether to use absolute or relative import.

Note : This is an unnecessary advanced function in using regular Python programming.

This function is called by the import statement. It is used to change the semantics of the import statement (by entering the __builtin__ module and assigning it to __builtin __.__ import__). However, now it is replaced by simpler use of import hooks, which will be introduced in another article. So using __import __ () is very rare, unless you want to enter the module only knowing each parameter name at runtime.

For example : The way __import __ () works in Python

 mathematics = __import__('math', globals(), locals(), [], 0) 

print(mathematics.fabs(-2.5))

Run the program, the result is:

 2.5 

See also: Built-in Python functions

Update 26 May 2019
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile