__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.globals
andlocals
: 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
You should read it
- The oct () function in Python
- The map () function in Python
- Max () function in Python
- Functions in Python
- Sum () function in Python
- The float () function in Python
- The next () function in Python
- The function set () in Python
- Zip () function in Python
- The ord () function in Python
- The input () function in Python
- Help () function in Python
Maybe you are interested
How to Communicate Well With People from Other Cultures What does the 'super slow' 7680fps movie recording feature on the Mate 30 Pro do? Hitman Sniper famous game is being free on iOS and Android How to create slow motion videos on Android? 8 ways to win people's hearts Changing these 10 ways of speaking will help you advance like 'windy kites'.