The syntax of __import__() function is:
__import__(name, globals=None, locals=None, fromlist=(), level=0)
This __import__() function is not necessary in everyday Python programming. It is rarely used and often discouraged.
This function can be used to changed the semantics of import statement as
import statement calls this function. However, it is always better to use import hooks.
If you want to import a module by name, use importlib.import_module() instead.
mathematics = __import__('math', globals(), locals(), , 0) print(mathematics.fabs(-2.5))
When you run the program, the output will be:
fabs() is a method defined in
math module. You can call this function using the following syntax:
However, using __import__() changed the way to access
fabs() in the above program.