Python __import__() Function
Description
__import__()This function is used to dynamically load classes and functions.
If a module changes frequently, you can use __import__() to dynamically load it.
Syntax
__import__ syntax:
__import__(name[, globals[, locals[, fromlist[, level]]]])
Parameter description:
- name -- Module name
Return Value
Returns a tuple list.
Examples
The following example demonstrates how to use __import__:
a.py file code:
#!/usr/bin/env python
#encoding: utf-8
import os
print ('In the a.py file %s' % id(os))
test.py file code:
#!/usr/bin/env python
#encoding: utf-8
import sys
__import__('a') # Import the a.py module
Execute the test.py file, and the output is:
在 a.py 文件中 4394716136Other Extensions
Python Built-in Functions