What does python's import mean?

藏色散人
Release: 2019-08-07 13:34:44
Original
32918 people have browsed it

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]]]])
Copy after login

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))
Copy after login

test.py File code:

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

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

在 a.py 文件中 4394716136
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!