__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 __ ():
name: the name of the module to import.globalsandlocals: used to determine name interpretation.fromlist: names of objects or sub-models should be entered from the provided module byname.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
Discover more
python function available python functions python documentation python learningShare by
Micah Soto
Update 26 May 2019
You should read it
- Max () function in Python
- Functions in Python
- Sum () function in Python
- The float () function in Python
- The next () function in Python
- The Quiet Details That Make a Sports Betting Platform Feel Reliable
- Instructions on creating toy set images with ChatGPT AI
- How are AI agents changing the journalism industry?
- How to fix SPOD error on Mac
- How to play Hi-Res sound on iPhone or iPad
- How to play PC games on Android devices using Parsec