Home  >  Article  >  Backend Development  >  What does python's import mean?

What does python's import mean?

藏色散人
藏色散人Original
2019-08-07 13:34:4432936browse

What does python's import mean?

What does python’s import mean?

__import__() function is used to dynamically load classes and functions.

If a module changes frequently, you can use __import__() to dynamically load it.

Recommended: [Python Tutorial]

Grammar

##__import__ Syntax:

__import__(name[, globals[, locals[, fromlist[, level]]]])

Parameter description:

name -- module name

Return value

Returns a list of tuples.

Example

The following example shows the use of __import__:

a.py File code:

#!/usr/bin/env python    
#encoding: utf-8  
 
import os  
 
print ('在 a.py 文件中 %s' % id(os))

test.py File code:

#!/usr/bin/env python    
#encoding: utf-8  
 
import sys  
__import__('a')        # 导入 a.py 模块

Execute the test.py file, the output result is:

在 a.py 文件中 4394716136

The above is the detailed content of What does python's import mean?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn