Python __import__()
The __import__() is a built-in python function that is used to call the import statement.
Python __import__()
The syntax of the import() function is:
1
__import__(name, globals=None, locals=None, fromlist=(), level=0)
import() Parameters
The import() function takes multiple parameters as argument:
- name - name of the module to import
- globals and locals - interpret names
- fromlist - Objects or submodules to be imported
- level - specifies whether to use absolute or relative imports
Example 1: How to use import() function in python?
1
2
mathematics = __import__('math', globals(), locals(), [], 0)
print(mathematics.fabs(-2.5))
Output:
1
2
3
4
5
6
7
8
9
10
11
<script type="text/javascript">
atOptions = {
'key' : '98858c4e91885e00ea9926beee01c03e',
'format' : 'iframe',
'height' : 90,
'width' : 728,
'params' : {}
};
</script>
<script type="text/javascript" src="https://www.highperformanceformat.com/98858c4e91885e00ea9926beee01c03e/invoke.js"></script>
2.5
This post is licensed under CC BY 4.0 by the author.