Python importThe () function
Description
import() The function is used to dynamically load classes and functions.
If a module changes frequently, you can use import() to load it dynamically.
Syntax
import Syntax:
__import__(name[, globals[, locals[, fromlist[, level]]]])
Parameter Description:
- name -- the module name
Return Value
Returns a list of tuples.
Example
The following example shows import Usage:
Code in the a.py file:
#!/usr/bin/env python
#encoding: utf-8
import
os
(
'
In the a.py file %s
'
%
id
(
os
)
)
Code in the test.py file:
#!/usr/bin/env python
#encoding: utf-8
import
sys
import
(
'
a
'
)
Import the a.py module
Execute the test.py file; the output is:
在 a.py 文件中 4394716136
Python built-in function